Excel compare columns and print value - excel

I am new to Excel so this is probably a rookie mistake but I'm stuck.
Basically I want a formula which matches data from column A with column B. If a match is found, then print into column C (at the same line as column A) data from column D (at the same line as column B).
Here are some mathematical examples:
If A1 = B3 then C1 = D3
or
If A5 = B2 then C5 = D2
I have tried looking this up on the net but my limited knowledge of Excel is a problem. The furthest I have come is this formula:
=IF(ISERROR(MATCH(A1,$B$1:$B$3,0)),"",D1)
This seems to see if A1 matches with any line in column B, and if it does, print D1 in C1. This is not what I want.
Thank you very much for your help in advance.

Function VLOOKUP is what you should use.
In following code, I assume that data is filled in range $A$1:$D$100.
Function to cell C1 is as follows (if all data in A column matchs some in B column)
=VLOOKUP(A1,$B$1:$D$100,3,false)
This function means:
search value of cell "A1" from $B$1:$B:$100, and pick value of cell in third column('D') of matched row.
You can copy this formula from cell C1 and past to C2:C100 to finish your work.
If some data in A column does not match any data in B Column, use function follows
=if(iserror(VLOOKUP(A1,$B$1:$D$100,3,false)),"NOT MATCH",VLOOKUP(A1,$B$1:$D$100,3,false))
Vlookup returns error if no match found, so returns "NOT MATCH" in the case.

Related

Excel using a range of cells to return value corresponding to an adjacent cell in the correct cell

I have been trying this for days, and can't get it correct.
I want to see if any value in column A matches any value in column C, and if so, return the value from column B into column D, BESIDE the match in column C.
I have tried all the suggestions for If, IFERROR, MATCH, VLOOKUP, etc, but can't get it to work. Any help would be most welcome!!
Here is a picture of my spreadsheet
Use a helper column:
In column D, use COUNTIF on each row to check the number of times that a cell in column A appears. =COUNTIF(C:C,A1).
In column E, use the formula =IF(D1>0, B1,"") and copy down
(you could of course combine these if you don't want to use the extra column)
Assuming you're starting in Row 1, in column D use:
=IF(COUNTIF($A:$A,$C1)>0,B1,"NO MATCH")
Drag that down as far as you need. This formula is saying: if the value in C1 matches anything in column A, then return the value from B1.
If this isn't what you mean, then please be clearer. Your data example is unreadable. Post a screenshot, or at least type it so it is in columns and rows. It's also unclear what you mean by "BESIDE the match in column C" What value is matching which value? That is, if A1 matches any value in C, do you want the value of B1 to show up in D1? Or do you want the value of B5 to show up in D5, if A1 matched C5?
In coumn D use formula
=IFERROR(VLOOKUP(C:C,A:B,2,0),"")
Note: this formula uses Implicit Intersection see here for some info

Is vlookup the correct thing to do to have the results next row

I'm using a vlookup to look for the all cells in the column D and see if they got a positive match in the C cells. If yes, I'm putting what is in the B cell next to the C cell.
In the example below, E2 will have what is inside of B2 after a lookup on D2 in the C column.
I've tried this formula but it is not the good one
=VLOOKUP(D2,C:C,0,FALSE)
I hope I don't need VBA
Best.
It is not completely clear exactly what you are looking for. I think you are trying to lookup data in column B based on a key in column C. If so what you want to use is
=INDEX(B:B,MATCH(D2,C:C,0))
As a breakdown, the MATCH will return a number representing which row within the range C:C matches the key D2. And, INDEX returns the element in B:B at row MATCH(D2,C:C,0).

making part of a statement iterative in Excel

I have a lookup that works for a single column:
=IFERROR(INDEX($C$2:$C$145,MATCH(A2,$D$2:$D$145,0)),"")
If A2 matches the range of values in D2 to D145, then output the corresponding C2 to C145 value in cell B2
This populates column B2 successfully.
How could I put that into a loop, so that $D2:$D145 iterates between column D and column GS
Really appreciate any hints from anyone at this point.
if its possible add column after gs and fill it with hlookup fomulas and then match by this column
hlookup formula for GT2:
=iferror(hlookup(a$2,indirect("D"&row(gt2)&":GS"&row(gt2)),1,0),"")
and copypaste it down until GT145; and your formula changes to:
=IFERROR(INDEX($C$2:$C$145,MATCH(A2,$GT$2:$GT$145,0)),"")

Run two vlookup if an 'N/A'

I am currently in the process of trying to create a vlookup function that will check cell A2 and check it on sheet1. If it brings back an error, it should go to B2 and then check on sheet1 and bring back the results.
This is what i currently have:
=IF(ISNA(VLOOKUP(A2,'Sheet1'!$A$2:$A$1932,1,FALSE)),"0",VLOOKUP(B2,'Sheet1'!$A$2:$A$1932,1,FALSE))
But it doesn't seem to be bringing back all the results, it is bringing back some results from each list A2 and B2.
What am i doing wrong?
Thanks in advance.
This should work:
=IFERROR(VLOOKUP(A2,'Sheet1'!$A$2:$A$1932,1,FALSE),VLOOKUP(B2,'Sheet1'!$A$2:$A$1932,1,FALSE))
It will use A2 to and try and find it in sheet1 and if it returns an error, it will go B2 and find the item on sheet1.
Try using:
=IF(ISNA(VLOOKUP(A2,'Sheet1'!$A$2:$A$1932,1,FALSE)),"0",VLOOKUP(A2,'Sheet1'!$A$2:$B$1932,2,FALSE))
Or you can use an IFERROR to make things shorter:
=IFERROR(VLOOKUP(A2,'Sheet1'!$A$2:$B$1932,2,FALSE),"0")
(You can omit the quotes around 0 if you mean a numerical 0 as opposed to a text 0)
This formula will get the value from column B in Sheet1 using the lookup value A2 from Sheet2 and looking it up in column A in Sheet1.
VLOOKUP checks the value of A2 in column Sheet1!A:A and returns the value from column Sheet1!B:B with the formula:
=VLOOKUP(A2,'Sheet1'!$A$2:$B$1932,2,FALSE)
^ ^
1 2
B is the result column
2 is in the index relative to A. A is column 1, B is column 2.
EDIT:
If you want to get the value from column A only, checking the value of A2 first and B2 on failure of the first, then you can use:
=IFERROR(VLOOKUP(A2,'Sheet1'!$A$2:$A$1932,1,FALSE),VLOOKUP(A2,'Sheet1'!$A$2:$A$1932,1,FALSE))

Excel: IF (cell C2 is not anywhere in column A OR not anywhere in column B) then return cell C2 in Cell D2

I have checked alot of INDEX and MATCH formula but can't nail this if someone can point me in the right direction to compare one cell in the C column against all cells in Column A and Column B and if it is in neither enter C2 in D2 so I have a list of numbers not in either column A or B.
So the idea is I check every C column cell against the other two columns and show the C cells that are in netiher.
Hopefully this pseudo code helps explain:
IF (cell C2 is not anywhere in column A OR not anywhere in column B) then return cell C2 in Cell D2
This one works for one column check:
=INDEX(C$2:C$23,MATCH(C2,A$2:A$23,0))
but I need two column check but the below does not work for me as it just says #N/A even for the row that was working for the single column check formula above. I I wondering if I can put an OR in the middle of the two matches or maybe you can suggest it a different way.
=INDEX(C$2:C$23,MATCH(C2,A$2:A$23,0),MATCH(C2,B$2:B23,0))
Thanks in advance.
Try using COUNTIF like this
=IF(COUNTIF(A$2:B$23,C2)=0,C2,"")
or if columns are not adjacent
=IF(COUNTIF(A$2:A$23,C2)+COUNTIF(B$2:B$23,C2)=0,C2,"")
Those will return C2 value if it's not in either column....otherwise a blank
....if you really want to use MATCH try this version....
=IF(COUNT(MATCH(C2,A$2:A$23,0),MATCH(C2,B$2:B$23,0))=0,C2,"")
And one more version using VLOOKUP:
=IF(AND(ISERROR(VLOOKUP($C$2,$A:$A,1,0)),ISERROR(VLOOKUP($C$2,$B:$B,1,0))),"",$C$2)

Resources