This is the problem i am facing in Excel formula
enter image description here
In column F, i want to find the common text across A2 to E2 (containing Blanks)
My Question:
Is there a simple way to get the result without VB?
Any help is appreciated,thanks
I found that google sheets has some really cool functions.
If you put the formula =SPLIT(A1, ",", TRUE,FALSE) in the cell after your row of common text (or probably even in a different sheet - "probably because hadn't tried it, though it should), the next x cells (where x is the number of "," in A1 - because "," is the delimitator) will be the text.
then you can put the code =IF(SUM(ARRAYFORMULA(if(REGEXMATCH($A$1:$D$1,F1),1,0)))=COUNTA($A$1:$D$1),F1,"") into an equal number of cells after that (probably should just put into the max number), and =CONCATENATE(I1:L1) into the last cell.
Ok. So to tweak this for yourself: I found that ARRAYFORMULA lets you put an array in place of a single cell in a function inside. how it exactly works I read its like a for loop. but I can't really vouch for that. but here it lets you have REGEXMATCH (which is a Boolean check on the cell you give it for if it contains the given REGEX) check each cell in the array.
the sum will add them up, and the if will match against the COUNTA to find if the number of cells in the array that contain this string is equal to the number of non-empty cells.
the concatenate at the end adds all the cells (containing the regex function) together, and since the only non-empty cells will be the one with the string, that is what this cell will return (no spaces).
code:
results:
the test data:
If you need in specifically Excel... this won't help.
We can use power query to achieve the desired result.
Unpivot the columns in Power query
Split all the columns by Comma delimiter
Create a custom column to see if the first column records exist in the remaining columns.
Use the functionText.contains.
Sample function: =Text.Contains([column.1],[column.1]&[column.2]&[column.3])
If the above function returns TRUE then get the first column result(This is the expected result) and load the data back to your excel
I'm trying to extract a word from a sentence if it starts with one of the following letters.Dell** or Samsung** or Apple**. The position of the words may vary in the cell.
A1: Dell2622 Retail34792 Lenovo StoreQuantity4
A2: Retail9858 Qty8 Samsung783546 Android
A3: Retail21512 Apple3411 StoreQty15 Macintosh
I am trying to use the following formula to extract the Dell** or Samsung** or Apple** if it's present int the cell.
=MID(A1, SEARCH({"Dell","Samsung","Apple"},A1), SEARCH(" ",A1, SEARCH({"Dell","Samsung","Apple"},A1))- SEARCH({"Dell","Samsung","Apple"},A1))
It works for the cell A1, but everything else returns #VALUE!. I guess it doesn't recognize that i want it to check for either or and extract either or. The result I'm trying to achieve is:
A1: Dell2622
A2: Samsung783546
A3: Apple3411
Later on i may need to add more things to search for, so I'm trying to keep it easily modifiable. I guess since it finds the first instance, then it's just a matter of tweaking something to ensure that if it didn't find the first value it looks for second, etc.
Assuming you have a data setup similar to the picture below, with your strings in column A, the formula in column B, and the words to look for in column D:
The formula in cell B2 and copied down is:
=TRIM(LEFT(SUBSTITUTE(MID(A2,MIN(INDEX(SEARCH($D$2:$D$4,A2&$D$2:$D$4),)),255)," ",REPT(" ",255)),255))
And per your request to not use a range reference and instead have the list of words directly in the formula:
=TRIM(LEFT(SUBSTITUTE(MID(A3,MIN(INDEX(SEARCH({"Dell","Samsung","Apple"},A3&{"Dell","Samsung","Apple"}),)),255)," ",REPT(" ",255)),255))
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")
I want make a formula which includes text and the output will be a different text also.
Like:
G8 = I am Red,
G9 = I am Green,
G10 = I am White.
Now, I need a formula which will give output like:
"Red" (in H8 field) when I enter "I am Red" and so on for other inputs.
I have tried with 'nested if', but only 7 nested if can be added, whereas I have at least 40+ values to input and need to get different output for those input.
Assuming your data is in column G starting G8, do the following:
Type in H8: =RIGHT(G8,LEN(G8)-MAX(IF(MID(G8,ROW(INDIRECT("1:"&LEN(G8))),1)=" ",ROW(INDIRECT("1:"&LEN(G8))),0))).
Press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
Autofill formula down your range.
It will return the last "word" in a string, or more exactly - part of string between the last space and its end, regardless of actual symbols.
Sample file: https://www.dropbox.com/s/dfkk1cqy1z0o3pz/ColorName.xlsx
A vlookup may work here. You would enter all data combinations, and then use vlookup, based on the "I am red" column, which would find the corresponding value in the table and return it. Depending on the type of data, you may have better success with the index and match method instead of vlookup.