Excel- How do I Find and Replace using the values from adjacent columns - excel

I'm a complete newbie to excel so apologies for my lack of knowledge!
I have a spreadsheet with 3 columnns.
Column 1 has cells with a range of values that can be repeated several times ie A B C A A D.
Column 2 has a list of the unique values in column 1 ie A B C D.
Column 3 contains the values that I would like to updated Column 1 with ie a b c d.
What I need to do is search Column 1 using Column 2 as an array of values when a match is found replace it with the adjacent value in column 3. Ie find all the A's in Column 1 and replace with a.
I did start writing a very long if statement if value = A replace with a etc but I have hundreds of unique values so I'm sure this isn't the most verbose way
Thanks in advance for your help

Consider the use of VLOOKUP
Result = Application.WorksheetFunction.Vlookup ( lookup_value, table_array, col_index_num, [range_lookup] )

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.

Counting instances across ranges in columns

I am creating a spreadsheet for my personal use. I need to count the number of times one column's values are equal to an adjacent column's.
Is there any way to do this in Excel without having to modify the formula every time a new row is added?
If you have column A and B now, add column C:
Column A Column B Column C
1 2 =countif(B:B, A1)
2 2
3 1
Then just copy the first value in column C, select the entire column C and paste :)
You will get:
Column C
1
2
0

How to return a value to the left of a table array with VLOOKUP?

I need help searching Column E for value=1 and return the value of column A for the same row. VLOOKUP isn't working because there are many columns being searched and there are several 1's in the lookup, and I couldn't seem to search just 1 column using VLOOKUP. Here's how my spreadsheet looks...
A B C D E
1 Name Weight WeightRank Height HeightRank
2 Mike 170 3 6.3 2
3 Richard 200 1 6.0 3
4 Charles 185 2 7.0 1
So I want to search column E for value=1 and return the corresponding value in column A, which in this example would search "HeightRank" for "value=1" and return "Charles"
I tried using =VLOOKUP(1,E:E,1) but that returns an error.
I tried using =VLOOKUP(1,A1:E3,1) but that returns an error.
INDEX(A:A,MATCH(1,E:E,0))
VLOOKUP doesn't work here -- it always searches in the first column of your table and returns a value of a column a given number of columns to the right.
The INDEX/MATCH combination is more flexible, letting you just choose the two columns you want. It's also easier to read (you don't have to count columns to see what it does) and it doesn't break if you insert or delete columns in between the ones you're using, which VLOOKUP does. If you use the trace-formula features, VLOOKUP also falsely implies that all the columns in between are precedents of your resulting formula. (Can you tell that I don't much like VLOOKUP? I just always use INDEX/MATCH and my life is easier for it.)
The OFFSET solution works but it's volatile, so you'll really bog down your worksheet if many cells depend on the result of your formula.
MATCH(x,E2:E4,0) returns the relative position of x in the range E2:E4. For example, MATCH(1,E2:E4,0) returns 3, because 1 is the value of the third cell in the range E2:E4.
OFFSET(A2,r,c) returns the cell r rows and c columns away from A2.
Thus you can say =OFFSET(A2,MATCH(1,E2:E4,0)-1,0) to return the value from column A corresponding to the cell in column E that contains 1.

Excel vlookup with two columns in source and target returning another column

I have a spreadsheet that has 4 columns sheet 1, and 5 columns sheet2 and I need to do a vlookup on Sheet1!a2&c2 and match the row in sheet2!a2&c2 and return sheet2!c5.
I think Index and Match would do it but all the examples have been matching a single value to an array which isn't what I need for eg.
Can't do attachments yet :( text it is sorry for the format
Sheet1
R1 A B C D
R2 2 D 3 Result will match sheet1!a2&c2 to sheet 2!A3&C3 and return Sheet2!e3 ie 34
Sheet2
R1 A B C D E
R2 2 F 5 GR 72
R3 2 X 3 FR 34
Any links or help?
Update
Sorry I wasn't clear I want to match the cobination of A2 and C2 in sheet 1,
ie in the example =sheet1!A2&sheet1!c2=23
to the values in sheet2!a2 plus sheet2!c2,
ie in this example =Sheet2!a3&Sheet2!c3=23,
and then return the value in Sheet2!E? , ie Sheet2!E3=34 here
I've done this before by creating a cheat column in sheet 2 = a2&c2 in say d2 and filling down then using, assuming 3 rows, however I can't create the cheat column in sheet2
=vlookup(a2&c2,sheet2!d2:e3, 2, false)
The rows sheet2! look like, sorry about the formatting
Picture attached, which I suddenly got to do , where I need to match the yellow columns in the lookup then return the brown column to sheet1!E2 but I can't add the cheat column Sheet2!d2:3 to the sheet cause the user is difficult :)
Thanks again. Any good tutorial on Index?
Try using LOOKUP like this
=LOOKUP(2,1/(A2=Sheet2!A$2:A$10)/(C2=Sheet2!C$2:C$10),Sheet2!E$2:E$10)
The two "tests", i.e.
(A2=Sheet2!A$2:A$10)
and
(C2=Sheet2!C$2:C$10)
return "arrays" of TRUE/FALSE values but when you divide 1 by one of those and then the other TRUE is converted to 1 and FALSE to 0 so you get a resulting array of either 1s (where both conditions are TRUE) or errors [#DIV/0!] where one or both are FALSE.
When you lookup 2 in that array it will never be found so it matches with the last 1, i.e. the match is with the last row where both conditions are satisfied...and the corresponding value from Sheet2!E$2:E$10 is returned. Another way is like this:
=INDEX(Sheet2!E$2:E$10,MATCH(1,(A2=Sheet2!A$2:A$10)*(C2=Sheet2!C$2:C$10),0))
which requires "array entry" with CTRL+SHIFT+ENTER

Compare two Excel columns, output cells in A that do not appear in B

I am trying to compare two columns in excel, A and B. Column A contains a complete list of customer numbers. Column B contains an incomplete list of the same customer numbers. So if a customer number is in A, but not in B then output that number to column C.
I'd use the MATCH function in combination with ISNA.
If I have the following table
A B C
1 4
2 3
3 1
4 7
5 2 5
6 6
7
I put in column 'A' the full customer list, and in column B is a random ordered partial list. I then put the function in C1 (and the rest of column C):
=IF(ISNA(MATCH(A1,B:B,0)),A1, "")
Now I see the values '5' and '6' only in column C, because those are the only two numbers that don't appear in column B.
In Cel C1 =IF(ISERROR(VLOOKUP(A1,$B$1:$B$10,1,FALSE)),A1,"")
Adjust for row counts and fill down against column A.
I think you're looking for something like this:
=IF(ISERROR(MATCH(A1,B1,0)),A1,"")
Propegate that formula along your new column and it'll reprint the populated Column A when Column B is a no match.
Reference URL: http://support.microsoft.com/kb/213367
(I believe I read the original question wrong, and am going on the assumption that column A and B are already sorted where the values will line up.)

Resources