Comparing two columns in excel, inserting blank rows moving associated data - excel

I have a large set of data in excel that needs to be matched by column. Specifically, the data currently looks like:
Column 1 Column 2 Column 3
1 1 aaaa
2 3 bbbb
3 4 cccc
4
Ideally, I want the data to look like:
Column 1 Column 2 Column 3
1 1 aaaa
2
3 3 bbbb
4 4 cccc
I've looked at different ways of comparing Column 1 and Column 2 (similar to this), but haven't found a good way to a) insert the blank space where column 1 and 2 don't match and b) also attach the data in column 3.
Any help would be greatly appreciated! Thanks!

If you want / can use directly Excel:
In the cells of Col "D" put this formula:
=IFERROR(MATCH(A2;$B$2:$B$8;);"")
In the cells of Col "E" put this formula:
=IF(D2<>"";INDEX($B$2:$C$8;D2;1);"")
In the cells of Col "F" put this formula:
=IF(D2<>"";INDEX($B$2:$C$8;D2;2);"")
Copy and paste for all the cells.
The good think it's that it's autoupdated... Or when finish copy and paste with value.

Related

How to find and replace from a List in Excel

Not using VBA but just simple excel, can anyone help me find a solution to this problem? Would greatly appreciate it!
I have a list of Names in Sheet 1 like below
-
A
1
sp_abc_Rick
2
sp_abc_Jabba_the
3
sp_abc_Dany
4
sp_random_Rick
5
sp_random_Jabba_the
6
sp_random_Dany
7
sp_constant
8
sp_ripley_art_Dany
9
sp_ripley_art_Jabba_the
10
sp_wakeup
I have a list of Mapping Table in Sheet 2 like below
-
A
B
1
Rick
Morty
2
Jabba_the
Hutt
3
Dany
Dragon
I wish to have a result in Sheet 1, in column B, like below
-
A
B
1
sp_abc_Rick
sp_abc_Morty
2
sp_abc_Jabba_the
sp_abc_Hutt
3
sp_abc_Dany
sp_abc_Dragon
4
sp_random_Rick
sp_random_Morty
5
sp_random_Jabba_the
sp_random_Hutt
6
sp_random_Dany
sp_random_Dragon
7
sp_constant
sp_constant
8
sp_ripley_art_Dany
sp_ripley_art_Dragon
9
sp_ripley_art_Jabba_the
sp_ripley_art_Hutt
10
sp_wakeup
sp_wakeup
To give you a context of the number of rows. Sheet 1 will be bigger with more than 1000 rows. Sheet 2 (Mapping Table) is constant set of rows. Currently it is about 100 rows.
You can use a formula like shown below using LOOKUP(), SEARCH() with SUBSTITUTE()
• Formula used in cell B1
=IFERROR(SUBSTITUTE(A1,LOOKUP(9^9,SEARCH($D$1:$D$3,A1),$D$1:$D$3),
LOOKUP(9^9,SEARCH($D$1:$D$3,A1),$E$1:$E$3)),A1)
There you go. There may have other better solution. This is what I got.
All in column B.
=IFERROR(CONCAT(MID(A1,1,MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE)-1),INDIRECT(CONCAT("sheet2!b", MATCH(MID(A1, MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE), LEN(A1)), Sheet2!$A$1:Sheet2!$A$300, 0)))),A1)
Break down is as follow;
Let's start put things from Column C onward.
Column C, to find the index of the first capital letter from the text.
ref: http://dailydoseofexcel.com/archives/2007/02/21/find-position-of-first-capital-letter-in-a-string/
=MATCH(1,(CODE(MID(A1,ROW($Z$1:$Z$255),1))<90)*(CODE(MID(A1,ROW($Z$1:$Z$255),1))>=65),FALSE)
Column D, cut the name part by using upper case letter index from column C, sp_abc_Jabba_the -> Jabba_the
=MID(A1, C1, LEN(A1))
Column E, search row number from Sheet2 by matching Column D's name with Sheet 2's Column A, this will get matching row number from Sheet2.
=MATCH(D1, Sheet2!$A$1:Sheet2!$A$300, 0)
Column F, get Sheet2's Column B value by the row number from Column E.
=INDIRECT(CONCAT("sheet2!b", E1))
Column G,
Cut "sp_abc_" from "sp_abc_Rick"
Concat "sp_abc_" with Column F's "Morty".
If there is any error, use Column A value as default.
. <- this dot is intentional. please ignore.
=IFERROR(CONCAT(MID(A1,1,C1-1),F1),A1)
Try:
Formula in B1:
=BYROW(A1:A10,LAMBDA(a,LET(b,TEXTBEFORE(a&"|","_"&A12:A14&"|",-1),IFERROR(CONCAT(IF(b&"_"&A12:A14=a,b&"_"&B12:B14,"")),a))))
The concatenation with a "|" would assert we only replace values when at the exact end of the input. Just in case there would be a stray (for example) 'Rick' somewhere before the end.

Average Vlookup values if it Cell X matches Cell Y in another sheet

So here's my problem:
I've got 2 sheets. (A and B).
2 Cells 2 Match (SheetA!A and SheetB!A)
6 Columns to average (B-C-D-E-F-G)
SheetA!A1 and SheetB!A1 If those two match, the average needs to be for cells B1-C1-D1-E1-F1-G1).
I've got a few thousands rows in each sheet. SheetA is the "Data Sheet" where all the data is. And SheetB is like my workbook, where all the stats will be.
I tried this function:
=AverageIf(SheetA!$A:$A;A2;SheetA!B:G)
I also tried
=average(index(SheetA!$B:$G;MATCH($A2;SheetA!$B:$G;0)))
Which doesn't seem to work either. But I know I probably made an error with this formula.
The function only gives me the value in cell B, it doesn't calculate the average for the 6 cells on the same row. Text1 and Text5 are the texts to Match from SheetB in SheetB
##SheetA##
A B C D E F G
Text1 1 2 3 1 2 3
Text2 2 3 1 1 1 1
Text3 1 1 2 1 2 2
Text4 3 5 2 4 5 1
Text5 4 2 2 2 2 2
##SheetB##
What I would like on SheetB:
A B
Text1 2
Text5 2.33
The formula I showed Previously gets me the following, it doesn't calculate the average, only gets me the first value:
A B
Text1 1
Text5 4
It matches the right row with Text1 from SheetA and SheetB.
Ok, this will work if you have the data as I show. If not, you need to adapt the MATCH part to make sure the formula will work.
Data in SheetA is like this, starting at row 1 (this is important):
My formula is in SheetB in column B, and is like this:
=AVERAGE(INDIRECT("SheetA!B"&MATCH(A1;SheetA!A:A;0)&":G"&MATCH(A1;SheetA!A:A;0)))
And I get this:
How this works:
MATCH will get the row number of the range you want to average (if found, ofc). Because my data starts at row 1, the number returned by MATCH is good. If your data does not start at row 1, you need to adjust it (+1,+2, whatever you need).
INDIRECT will return the range in same row, but between columns B and G from SheetA
Finally, AVERAGE will make the average.
There is no error handling if something is not found, but if you need it, just add something like IFERROR.
Also, MATCH will only work if the match is 100% exact. In your example in SheetA you have Text1 but in SheetB you typed Text 1, which are not equal. Make sure you type them right.
Hope you can adap this to your needs.

how to expand list into pattern in Excel?

I have a list like this:
1
2
3
4
5
I am pulling those numbers into another spreadsheet, using vlookup.
I want to create a new list or pattern, that looks like this:
1
1
1
1
1
2
2
2
2
2
3
3
3
3
3
.. etc
How can I do that easily (my first list has 300 items, so dont want to do by hand)
Thanks!
Following the Scheme:
use the formulas:
C2 -> =A2
C3 -> =INDEX(A:A;ROUNDDOWN((ROW(G1)/$B$2)+2;0)) ' And Autocomplete
D2 -> =IF((ROUNDUP(ROW(G1)/($B$2+$B$4);0))-(ROUNDDOWN((ROW(G1)/($B$2+$B$4))+($B$4)/$B$2-$B$4/10;0))=1;INDEX(A:A;ROUNDDOWN((ROW(G1)/($B$2+$B$4))+2;0));"") ' And Autocomplete
The C column it's relevant to repeat without blanks, the column D it's relevant to the repeat with blanks.
In the cells B2 put the number of repetition and in the cell B4 put the blanks cells.
If you have more that one column to copy use the same code for every column...
If you need to have only values, at the end copy and paste with value ...
Warning: The formula in column D work with low number of blanks and Repeat... Eventually you need to recalibrate.

A function that will lookup a reference

Before I get started thanks for taking your time and helping.
This is what my worksheet looks like:
Row # B C D E F
2 1 Product 1 B2 B3 B4
3 2
4 6
5 1 Product 2 B5 B6
6 5
7 4 Product 3 B7
I was trying to follow this formula: (The best answer one or green check mark) return values from multiple matching rows
I got all the way to the =IFERROR(INDIRECT(lookups!H5),"") but can not get this to work.
What I am tying to do is order the numbers in Column B to go to the right of the product. Which I was able to get the column it is in (B) and the row number it is in (B2). I would like to change the value (B2) to the number that is there.
I would like it to look like this:
Row # C D E F
2 Product 1 1 2 6
3
4
5 Product 2 1 5
6
7 Product 3 4
If someone could help explain this to me or find a better way that would be great.
Not sure what is to happen to columnB but if you replace B with "="B throughout columns D:F then select each of these in turn and apply Text to Columns with Tab as the delimiter the 'cell references' convert to formulae referring to the values in B. If you want to delete columnB copy D:F and Paste Special, Values over the top.

Find value from one cell, copy value from cell near to that cell and paste it to another sheet

I have 2 sheets with different values. I need to find a value from one cell.sheet1 in sheet2 and copy value from nextcell_in_the_same_row.sheet1 to nextcell_in_the_same_row.sheet2.
It is very difficult to explain let look at the example bellow.
E.g.
Before
first sheet:
A B
1 aaa 123
2 bbb 456
3 ccc 789
4 ddd 122
second sheet:
A B
1 aaa
2 ada
3 cca
4 ccc
After
first sheet:
A B
1 aaa 123
2 bbb 456
3 ccc 789
4 ddd 122
second sheet:
A B
1 aaa *need to find value in the first sheet and copy value from B2 because aaa in A1*
2 ada *value does not exist in the first sheet so copy nothing*
3 cca *not need to copy because no value in the first sheet*
4 ccc *need to copy the value from B3*
Thank you so much!
Use a VLOOKUP along with an IFERROR.
=IFERROR(VLOOKUP(A1, Sheet1!A:B, 2, 0), "")
This will do what you described (well described, by the way!) in your question. Drag the formula down in Sheet2 till the bottom.
VLOOKUP takes the value of A1 in sheet 2 (no sheet reference because the value is in the same sheet as the formula) and looks it up in column A of Sheet1.
It returns the second value (hence why 2) of the table selected in the formula (column A is 1, column B is 2).
The 0 tells the VLOOKUP to look for exact matches. You don't need approximate match here.
And IFFERROR is there in case VLOOKUP doesn't find anything (like with ada) and instead of giving #N/A, returns an empty cell, "".

Resources