I have an Excel 2010 document which has hundreds of rows each with a cell as below:
(without the quotes, of course)
"XX - A Name of Something Here"
Which I need to change to:
"A Name of Something Here (XX)"
I'm trying to figure out the best way to accomplish this and could really use some assistance.
Try this:
=RIGHT(A3, LEN(A3) - 5) & " (" & LEFT(A3, 2) & ")"
which means
all but the last 5 chars of the string, counting from right to left
5 because XX space dash space is 5 chars long
a space and an open parenthesis
the leftmost two chars ie XX
a close parenthesis.
This formula will work given your example
=MID(A1&" ("&A1,5,LEN(A1))&")"
How about:
=MID(A1,3,9999) & "(" & LEFT(A1,2) & ")"
but how about the dash??
=RIGHT(A1, LEN(A1) - 5) & " (" &LEFT(A1, 2) & ")"
This will work too - I like "concatenate" since I don't need to keep track of the &'s
=CONCATENATE(RIGHT(A3,LEN(A3)-5)," (", LEFT(A3,2),")")
So many fun ways to do the same thing...
Related
Column A - first name list
Column B - last name list
Column C - salutation list
I want in column D: HI "salutation" + first name + last name!
I try ="Hi &C1&" "&A1&" "&B1&"!" -> result Hi Mr. Brad Pitt!
But I want the result Hi "Mr." Brad Pitt!
You can use two double quotes where you want each double quote to be, in order to escape it.
="Hi """&C1&""" "&A1&" "&B1&"!"
you can use 2 double quotes to get a double quote in your text.
Try this instead: ="Hi """&C1&""" "&A1&" "&B1&"!"
Try below formula-
="Hi " & CHAR(34) & C1 & CHAR(34) & " " & A1 &" "&B1&"!"
I recently ran into an issue when using VBA to insert a formula into an Excel sheet. Below the relevant piece of code;
Calculatie_cell.Offset(n, 5) = "=SOM(H" & (n + 3 - 1) & ":H" & (n + 3 - Onderdelen_aantal) & ")"
Calculatie_cell.Offset(n, 8) = "=SOM(K" & (n + 3 - 1) & ":K" & (n + 3 - Onderdelen_aantal) & ")"
For the first iteration where it triggers, the expected output is;
=SOM(H4:H7)
=SOM(K4:K7)
The output I recieve is;
=#SOM(H4:H7)
=#SOM(K4:K7)
This output yields a #NAME? error. Pressing F2, enter on the cell (like inputting it by hand), gives an error stating that this formula is not supported by older versions of Excel with the option to correct it to the expected output. If I accept this it works.
I can't find why Excel thinks it needs the # and the code below does not filter the # from the formule (but it does filter it out of random text with an #)
Calculatie_cell.Offset(n, 5) = Replace(Calculatie_cell.Offset(n, 5), "#", "")
Calculatie_cell.Offset(n, 8) = Replace(Calculatie_cell.Offset(n, 8), "#", "")
Does anyone have a suggestion how I can get rid of the #, or another way to make the formula work? Thanks in advance!
Relevant note; I use Excel 2016 in Dutch, meaning "SOM" is the correct way to spell "SUM"
First of all, regardless of your Office installation language, VBA asks for engligh input.
Therefore, replace SOM by SUM in your code.
It should appear as SOM in the workbook, but not in the code.
Second of all, using oCell = "=SOME_FORMULA" usually does not yield the intended result.
Instead, one should use oCell.Formula2 = "=SOME_FORMULA".
This is why an # shows up in the formula.
See this article for information.
Finally, your code should be
Calculatie_cell.Offset(n, 5).Formula2 = "=SUM(H" & (n + 3 - 1) & ":H" & (n + 3 - Onderdelen_aantal) & ")"
Calculatie_cell.Offset(n, 8).Formula2 = "=SUM(K" & (n + 3 - 1) & ":K" & (n + 3 - Onderdelen_aantal) & ")"
User #Solar Mike was right.
Even though Excel wants the code to be "SOM" (Dutch spelling), in VBA it needs to ben SUM (English spelling). It auto-translates and works right of the bat. Thank you for your help!
If you post it as an answer, I will accept it as such.
I'm working from a software that stores some entity IDs and need to format them in a very specific way. I'll try to be as specific as possible.
Each cell has to be 6 digits long.
1st digit can be either alphabetical or numeric.
2nd, 3rd, and 4th digit can only be numeric.
5th and 6th digit can only be alphabetic.
I have some of the following IDs (and what i need them to look like) for example (substituting - for spaces):
G11R(G-11R-), J6R(J--6R-), I6AR(I--6AR), 1516B(1516B-), 414(-414--).
I don't even know where to begin on something like this, I've searched the forum but I'm also not even sure exactly what you would call this.
Any help, even just a point in the right direction would be greatly appreciated.
Thanks
Because I wanted to see if I could do it with a formula:
=LEFT(IF(OR(ISERROR(--LEFT(A1)),AGGREGATE(14,6,ROW(INDIRECT("1:" & LEN(A1)))/(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))),1)-AGGREGATE(15,6,ROW(INDIRECT("1:" & LEN(A1)))/(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))),1)=3),LEFT(A1)," ") &REPT(" ",MAX(2 - (AGGREGATE(14,6,ROW(INDIRECT("1:" & LEN(A1)))/(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))),1)-AGGREGATE(15,6,ROW(INDIRECT("1:" & LEN(A1)))/(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))),1)),0)) & RIGHT(MID(A1,AGGREGATE(15,6,ROW(INDIRECT("1:" & LEN(A1)))/(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))),1),AGGREGATE(14,6,ROW(INDIRECT("1:" & LEN(A1)))/(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))),1)-AGGREGATE(15,6,ROW(INDIRECT("1:" & LEN(A1)))/(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))),1)+1),3) & MID(A1,AGGREGATE(14,6,ROW(INDIRECT("1:" & LEN(A1)))/(ISNUMBER(--MID(A1,ROW(INDIRECT("1:" & LEN(A1))),1))),1)+1,LEN(A1))&" ",6)
Just to show, I replaced all the spaces in the formula with -.
I'm trying to find if cells have specific string or not. This is how I do it right now:
=IF(ISNUMBER(SEARCH("AAA";L2)); "yes"; "no")
If a cell has "AAA", I write to another cell yes, if not, I write no...
The problem is that it also gets true answer for AAA1 or AAA1234 for an example, how can I return true statement only for AAA?
If there are trailing numbers/charcters in my string, I want to reutrn no, but the cell itself might be longer... for and example "AAA BVC BFD2" etc. Then I want to return true. False if for an example: "AAA1 BVC BFD2"
As I mentioned in comments, you can use this one:
=IF(ISNUMBER(SEARCH(" AAA ";" " & L2 & " ")); "yes"; "no")
How it works:
suppose you have a string "AAA BVC BFD2" in cell L2.
" " & L2 & " " part modifies this string to " AAA BVC BFD2 " (note, there're additional spaces in the end and in the beggining)
now, we're able to search " AAA " (with spaces) in modified string " " & L2 & " ".
I'm clearly missing something as it seems to me that you could do this with something as simple as
=IF(LEFT(A1,4)="AAA ","yes","no")
I don't think the question is particularly clear, if I'm being honest...
I am trying to generate a customer number using the first three letters of the customers last name, the first name initial and middle initial, followed by the last four of their phone number. How would I do this? All I need is the formula.
First_Name Middle_Initial Last_Name Street_Address City State Zip Phone
Nathaniel E. Conn 6196 View Ct Lancing TN 37770 567-273-3956
Something like this (assuming a table with [structured-references], fill in the actual cell names if not):
=LEFT([LastName] & "---", 3)
& LEFT([FirstName] & "-", 1)
& LEFT([MiddleInitial] & "-", 1)
& RIGHT([PhoneNumber] & "----", 4)
I have used dashes ("-") to fill in any spaces where the field might be smaller than the number of characters you need from it. You can change them to any fill character that suits you.
Well, it depends on if each piece of data has its own column, looks like it does.
You can use the left/right functions to parse the data out of your columns.
=CONCATENATE(RIGHT(C1,3) & LEFT(A1,1) & LEFT(B3,1) & RIGHT(H1,4))
I would do:
=MID(CELL_LAST_NAME;1;3)&MID(CELL_FIRST_NAME;1;1)&MID(CELL_MIDDLE_NAME;1;1)&MID(CELL_PHONE;LEN(CELL_PHONE)-3;4)