I understand the basic use of the vlookup with wildcard but I'm running into a problem lately.
I need to lookup a value that contained in a cell as a part of string. In the below Sample I look up colA in the colC, with should be found, then return the values in col D into col B.
I use =VLOOKUP("*"&A1&"*",C$1:D$2,2,0), and it only works for B1.
Why do B2 & B3 don't work out the same way? Any solution?
Sample:
As per your investigation and comment by Axel, VLOOKUP doesn't work with values over 255 characters in length. A workaround is use an array formula with the SEARCH function which handles much longer values. Double click into cell B1 and paste this formula, then save it by pressing CTRL + SHIFT + ENTER instead of just pressing Enter by itself:
=INDEX($D$1:$D$2,MATCH(TRUE,ISNUMBER(SEARCH(A1&",",$C$1:$C$2&",")),0))
If you enter it correctly, selecting the cell will show {curly braces} around the formula and it should evaluate to your desired result.
This formula first creates an array searching for the position of A1 in every cell in C1:C2. The array will consist of numbers (when A1 is found) and errors (when A1 is not found).
ISNUMBER then creates an array of TRUE (when A1 is found) and FALSE (when A1 is not found)
MATCH then finds the first TRUE value in the array.
INDEX then returns the corresponding value from the D1:D2.
Edit: The formula now searched for the value in A1 followed by a comma. This ensures that an exact match is made. To also ensure that the formula can match against the last value in any cell in column C, a comma is also added to the end of the values in column C.
I have a scenario where I want my Microsoft excel field to have the same length of the longest word in the column.
Basically lets say if I have:
ACBBASDBBADSAD
BADFDFDDF
So here I want to have the second word with less characters to have white spaces at its end to match the length of the first word.
=&" " this definitely helps but I am unable to achieve the above scenario
Consider this screenshot:
In column B the length of each cell of column A is established with the formula =len(A1) copied down.
Cell D2 has the range name MaximumLength and the formula =max(B:B).
With that in place, you can create the padded values with this formula in cell G1, copied down:
=A1&REPT("*",MaximumLength-LEN(A1))
If you don't want to use the helper column and helper cell, you can use this array formula instead:
=A2&REPT("*",MAX(LEN(A1:A15))-LEN(A2))
This formula must be confirmed with Ctrl-Shift-Enter. It is advisable to use defined ranges, not whole columns in array formulas, hence the range in LEN(A1:A15). Adjust as desired.
I've used the "*" character so it is visible. Replace it with a space " " in your scenario.
You can add this formula to count maximum characters and use on some cell, because you will need to press a command for it to work, so every cell can't contain this formula, let's say it is on Z1:
=MAX(LEN($A:$A))
Certify to press ctrl+shift+enter on the formula
Then you use this formula on your cells:=REPT(" ";Z1-LEN(A2))&A2
Edit: Sorry, anwsered late, teylyn is more complete.
How can I extract the first word of a number of different cells and have each of the first words show together in one other cell separated by comma?
e.g. A1 shows "Firstname1 Lastname1", A2 shows "Firstname2 Lastname2", A3 shows "Firstname3 Lastname3",
I need a formula allowing me to show the following in cell D2 "Firstname1, Firstname2, Firstname3"
I found this solution, which gives me the first word of one cell and shows it in another cell but I don't know how to get the first word of a number of cells and show them all coma separated in another cell
=LEFT(A1,SEARCH(" ",A1)-1)
Excel function to get first word from sentence in other cell
Thanks!
What if instead of just three cells you have an Excel range A1:A100 which has all the names? How would you concatenate in such an instance? Will you type that long a formula?
As Jerry suggested, VBA is Apt for this. But what if you do not want to use VBA or long formulas?
See this example. I am taking 10 cells for the sake of explaining.
Let's say the data looks like this.
Now select the entire column and click on Data~~>Text To Columns
When you click finish, the output will be like this
Now in cell say E4, type this =Transpose(A1:A10). Replace A1:A10 with the actual range. However do not press the Enter key. Press the key F9. You will see that all the first names are now visible.
Simply copy that and press Esc. Now open Notepad and paste it there.
Next delete the { and the }
Next manually replace "," by , and you will get what you wanted.
=LEFT(A1,SEARCH(" ",A1)-1) &", "&LEFT(A2,SEARCH(" ",A2)-1)&", "&LEFT(A3,SEARCH(" ",A3)-1)
using your current formula, =LEFT(A1,SEARCH(" ",A1)-1), you can add the value of subsequent cells to the previous calculation, and build the comma separated values.
in B1, we have your original formula, =LEFT(A1,SEARCH(" ",A1)-1)
in B2 we concatenate the previous result, and add on the comma and the new word:
=B1 & "," & LEFT(A2,SEARCH(" ",A2)-1)
copy this to B3 (and on) and you will slowly see the full list getting created.
The last value is the one you want, so, in C1, put the formula
=OFFSET(B1,COUNTA(B:B)-1,0)
(and hide column B so it looks better)
I have a column filled with data that has a path. I'd like to get the last element in the path, the second last element, and the first element. For example, for the following data:
\Product\Release\Iteration
\Product\Folder1\Folder2\Anotherfolder\Release2\Iteration5
\Product
\Product\Somefolder\Release3\Iteration5
I'd like to get the following in cells
In cell B1: "Product", cell C1: "Release", cell D1: "Iteration"
In cell B2: "Product", cell C2: "Release2", cell D2: "Iteration5"
In cell B3: "Product", cell C3: blank, cell D3: blank
In cell B4: "Product", cell C4: "Release3", cell D4: "Iteration5"
Getting the first and the last component is easy. I'm mostly just struggling with getting the second to last component (column C in the example above).
In B1 and copied down:
=TRIM(MID(SUBSTITUTE(A1,"\",REPT(" ",99)),99,99))
In C1 and copied down:
=IF(LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))=2,TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),99)),IF(LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))>2,TRIM(LEFT(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),198),99)),""))
In D1 and copied down:
=IF(OR(LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))={1,2}),"",TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",99)),99)))
Assuming your data is in ColumnA use Text to Columns with \ as delimiter to split across columns B:G. Assuming a maximum of 8 elements, put =B1 in K1 and in L1:
=IF(AND(ISBLANK(D1),ISBLANK(C1)),"",IF(ISBLANK($D1),$C1,IF(ISBLANK(C1),"",INDIRECT("R"&ROW()&"C"&COLUMN()-COUNTBLANK($B1:$I1)-4,0))))
Copy L1 to M1 and K1:M1 down to suit.
Copy Paste Special Values over the top and delete columns A:I.
Made up two formulas to retrieve any part of the path you want:
Taking the first as starting from the left:
=IFERROR(MID(A3,FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),C$2))+1,IFERROR(FIND("\",A3,FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),C$2))+1)-FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),C$2))-1,LEN(A3))),"")
Taking the first as starting from the right:
=IFERROR(MID(A3,FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))+1-D$2))+1,IFERROR(FIND("\",A3,FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))+1-D$2))+1)-FIND(CHAR(1),SUBSTITUTE(A3,"\",CHAR(1),LEN(A3)-LEN(SUBSTITUTE(A3,"\",""))+1-D$2))-1,LEN(A3))),"")
And here's a google spreadsheet where you can see how it's working.
Note: I had to make a few changes to the formulae to make it google-spreadsheet-compatible, namely:
Change CHAR(1) to something else, I used "/" as substitute
Add an IF() to check for SUBSTITUTE(,,,0) (the 0 parameter) since this gives an error in MS Excel but not on google spreadsheet.
If you just need to parse the data to cells, you could import a text file into Excel with '\' delimitor. Otherwise, you need to loop through with CHARINDEX() and SUBSTRING to find the position of each backslash and parse out the data in between.
You could also use SSIS and set up a text file transformation with '\' delimitor to Excel for automation. With TSQL, you need to loop as I suggested
This has an excellent example that uses the split command. You just need to change the | character to \ and use the loop to put the individual values in the places you want.
Break string based on a character in VBA 2010
This should work for you (assuming you don't use * in your file names which I don't think is allowed in windows anyways):
=RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,"\","*",(LEN(A2)-LEN(SUBSTITUTE(A2,"\","")))-1),1))
That is for the second last element.
You can get any element you want by changing the bold number:
=RIGHT(A2,LEN(A2)-FIND("",SUBSTITUTE(A2,"\","",(LEN(A2)-LEN(SUBSTITUTE(A2,"\","")))-3),1))
EDIT/ADDITION
If you want to get rid of the values to the right of the nth element in the formulas above, you can do it like this:
=IFERROR(LEFT(RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,"\","*",(LEN(A2)-LEN(SUBSTITUTE(A2,"\","")))-1),1)),FIND("\",RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,"\","*",(LEN(A2)-LEN(SUBSTITUTE(A2,"\","")))-1),1)),1)-1),"error checking, lol")
A field in Excel contains words separated by semicolons, e.g.:
A1 = save;the;national;treasure;for;good
How can I apply Excel text formulas to produce separate words from this field in another fields? E.g.:
A2 should contain a formula to get the first word ("save")
A3 should contain a (different) formula to get the second word ("the")
etc.
However these formulas should hold good even when the value in A1 changes, e.g. if the value of A1 is changed to
A1 = hello;there;how;are;you
Any help in this respect will be highly appreciated.
(The problem is writing a function of my own is not allowed in this case, I have to use original functions like find, search, mid, etc.)
You can create a VBA function to split the fields from this example:
Function ExtractElement(str, n, sepChar)
' Returns the nth element from a string,
' using a specified separator character
Dim x As Variant
x = Split(str, sepChar)
If n > 0 And n - 1 <= UBound(x) Then
ExtractElement = x(n - 1)
Else
ExtractElement = ""
End If
End Function
Then the A2 formula would be: =ExtractElement(A1, 1, ";") and A3 would be: =ExtractElement(A1, 2, ";") and so on
If you have your text to parse in A1 then the following formulas should work
In A2 enter the formula
=IF(ISERROR(LEFT(A1,FIND(";",A1)-1)),A1,LEFT(A1,FIND(";",A1)-1))
In B2 enter the formula
=IF(ISERROR(RIGHT(A1,LEN(A1)-FIND(";",A1))),"",RIGHT(A1,LEN(A1)-FIND(";",A1)))
You can then copy those down as far as you need. Column A grabs the left most word, and Column B displays the remaining string to be parsed. If it runs out of words to parse the formula will display a blank. Column B can also be hidden.
If you can use intermediate formulae, then this will work:
A1 -- save;the;national;treasure;for;good
B1 -- blank
C1 -- =IFERROR(FIND(";",$A1,1+(B1)),LEN($A1)+1)
copy C1 into D1:H1
C2 -- =MID($A1,B1+1,(C1-B1)-1)
copy C2 into D2:H2
Row 1 will display the position of each semi-colon in A1, because it starts looking in the string one character past the semi-colon found in the previous cell.
eg cell E1 searches for a semi-colon in A1 starting at D1+1 =10.
The iferror statement in C1:H1 traps the error which will occur when the search finds no further semi-colons, and returns the full length of string A1, plus 1 for an imaginary semi-colon at the end.
B1 needs to be blank to create an initial zero.
Cells C2:H2 then use the Mid function to copy the section of the A1 string starting one character after the value in each of B1:G1, with length (C1-B1)-1, (d1-c1)-1 etc (minus one to cut out the semi-colon itself)
You should get: 5, 9,18,27,31,36 in Row 1, and beneath those cells the individual words.
Hope this helps.