Match and concatenate formula? - excel

I have two excel columns. I need to compare the two columns (A & B) for matches and append everything after the delimiter, like so:
Column A
123456;cc01
654321;cc02
333333;cc03
444444;cc04
555555;cc05
Column B
111111
222222
333333
444444
555555
The output should be the following due to three matches in this example:
Column C
333333;cc03
444444;cc04
555555;cc05
Thanks in advance for your help!

Try this array formula (line break added for readability):
= IFERROR(INDEX($A:$A,SMALL(IF(($B$2:$B$6-LEFT($A$2:$A$6,FIND(";",$A$2:$A$6)-1))=0,
ROW($A$2:$A$6)),ROW($A2)-MIN(ROW($A$2:$A$6))+1)),"")
Note this is an array formula, so you have to press Ctrl+Shift+Enter instead of just Enter after typing the formula.
See working example below. I have this formula in cell C2 and dragged down.
This formula also works if you insert rows with new data. See below.

Or this regular entered formula:
=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($A$1:$A$6)/(ISNUMBER(MATCH(--LEFT($A$1:$A$6,FIND(";",$A$1:$A$6 & ";")-1),B:B,0))),ROW(1:1))),"")
Put in the first cell and copy down.
to deal with ever enlargin data use this:
=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($A$1:INDEX(A:A,MATCH("zzz",A:A)))/(ISNUMBER(MATCH(--LEFT($A$1:INDEX(A:A,MATCH("zzz",A:A)),
FIND(";",$A$1:INDEX(A:A,MATCH("zzz",A:A)) & ";")-1),B:B,0))),ROW(1:1))),"")

Related

excel partial match in any of the lookup data

I have data in column A and B have lookup data.
For A2 (FY|F|V|D|Safety|3M). take the B column first value and search whether there is any match if not take second value in B column and repeat the process for all the B column values and if there is match print the B column value in Result. Does that make sense?
I tried with VLOOKUP but no luck. Please help me.
Columns:
A B(Lookup) C(Result)
FY|F|V|D|Safety|3M Toro 3M
FY|F|V|D|POP|ToroDays 3M Toro
FY|F|V|D|Lumber|GroundContact honeywell NA(Not available)
FY|F|V|D|airfilters|honeywell samsung honeywell
Enter the following formula in Cell C2
=IFERROR(INDEX($B$2:$B$5,MATCH(TRUE,IF(FIND($B$2:$B$5,A2)>0,TRUE),0)),"NA")
This is an array formula so commit it by pressing Ctrl+Shift+Enter. Drag/Copy down as required. Change range as needed.
See image for reference.
NOTE : Above formula is case-sensitive. If you want non-case-sensitive result you can use following formula.
=IFERROR(INDEX($B$2:$B$5,MATCH(TRUE,IF(FIND(UPPER($B$2:$B$5),UPPER(A2))>0,TRUE),0)),"NA")
In C2, put this and drag down:
=IF(ISERR(SEARCH($B2,$A2)),"N/A",$B2)
Here you go. A Google docs spreadsheet you can see.. The screenshots are from it.
Formulas
Results
You could have string with Toro3M in it, or all 4 for that matter.
The solution I have solves that. But you'd need to tweak to add commas or some such seperator.. And conditionally do it if cell in column F-I are zero length.

Excel duplicate rows to CSV cell formula

I have an Excel spreadsheet such as this: (See Columns A through D of "Formula Output Column E" image - had to remove original 1st image due to not enough reputation points)
And would like to make a formula to consolidate it so that when the first three columns are duplicates, the last column gets combined into one CSV cell such as this: Excel Finish
I'm thinking it can get there with the right combination of Index and Match functions, but I haven't gotten it to work yet.... any help would be much appreciated! Thanks.
I currently have the following formula:
=IF(AND(A2=A1,C2=C1),"",D2&",
"&INDEX(A2:D17,MATCH(A2,A2:A17,0)+1,4)&",
"&INDEX(A2:D17,MATCH(A2,A2:A17,0)+2,4)&",
"&INDEX(A2:D17,MATCH(A2,A2:A17,0)+3,4)&",
"&INDEX(A2:D17,MATCH(A2,A2:A17,0)+5,4))
Which yields this ouput in Colum E: Formula Output Column E
As you can see, it either includes too many rows (Row 2 and 6 output) or too few (Row 8 output). Hope this helps, thanks.
If you have two extra columns and type
=IF(AND(A2=A3,C2=C3),D2&","&E3,D2)
in cell E2 and
=IF(AND(A2=A1,C2=C1),"",E2)
in cell F2 like in the following example
Then you will get the output for column CSV Output correct but in row F instead of row E, as below when you fill the formula to the bottom.
Here is the array formula (means you have to click Ctrl + Shift + Enter altogether) you can use in your CSV Output column:
{=IF(OR(ROW(E1)=1,MAX(--($A$1:A1=A2)*--($B$1:B1=B2)*--($C$1:C1=C2)*ROW($A$1:A1))=0),D2,INDEX($E$1:E1,MAX(--($A$1:A1=A2)*--($B$1:B1=B2)*--($C$1:C1=C2)*ROW($A$1:A1)))&", "&D2)}
Here is the explanation but I also included a picture for your reference:
Column F: This is to find the last matched row and this is also an array formula:
{=MAX(--($A$1:A2=A3)*--($B$1:B2=B3)*--($C$1:C2=C3)*ROW($A$1:A2))}
The -- just easy to see when you evaluate formulas. You can remove them if you want.
Column G: This is to concatenate the prior outcome:
=IF(OR(ROW(G1)=1,F2=0),D2,INDEX($G$1:G1,F2)&", "&D2)
Hope this helps. Please let me know if you have any question.

Summing numeric portion of cell when alpha portion of cell is the same

I have a spreadsheet that has columns for dates and the values can be either "1v, .5v, 1p, .5p, 1s, .5s"
I have 3 columns in each row one for each letter "v, p and s". I want to be able to add the total of all cells in the range grouped by letter and then display the sum for each letter in it's respective column (v, p or c).
Here is an example of the sheet:
Name Vacation Personal Sick 1/5/15 1/6/15 1/7/15 1/8/15
Billy 1.5 1 0 .5v 1v 1p
It is the formula that goes in the vacation/personal/sick cell that I just can't figure out.
I went down the array formula route and came up with essentially the same formula as #Sancho.s :-
=SUM(LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v"))
You could modify it to take account of blanks:-
=SUM(IF($E2:$H2<>"",LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v")))
Perhaps this would be better, to ignore any mis-formatted cells:-
=SUM(IFERROR(LEFT($E2:$H2,LEN($E2:$H2)-1)*(RIGHT($E2:$H2)="v"),0))
These all have to be put in with Ctrl-Shift-Enter.
Assuming the range you posted starts at A1, use
=SUMPRODUCT((RIGHT($E2:$G2,1)="v")*LEFT($E2:$G2,LEN($E2:$G2)-1))
in B2. Change "v" and the range to use suitably.
Pro:
It is not an array formula. See why this may be important
Con:
I could not make it work with blank cells.
This "array entered" version will also allow blanks
=SUM(IF(RIGHT(E2:G2)="v",SUBSTITUTE(E2:G2,"v","")+0))
confirmed with CTRL+SHIFT+ENTER

excel first word from cells in other cell

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)

Getting the Nth instance of an element

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")

Resources