VLOOKUP matching on more than one condition

JadonR

Board Regular
Joined
Apr 15, 2009
Messages
154
Office Version
  1. 365
Hey guys. I've used VLOOKUP's in the past but this seems a bit more complicated than that. Essentially I would like to use a formula to populate Column 'H' on the sheet named UPCS Export (see highlighted field in first image below) with the value in the 'K' column from the IM_BARCOD sheet (see second image below). The difficult part is that it needs to also match on two other columns. The values in UPCS Export, Column 'B' should match the number in IM_BARCOD, Column A. It should also match UPCS Export, Column 'E' on IM_BARCOD, Column 'C'. If there is NO MATCH, then the number in Column H should be incremented in sequence based on the highest number. See last image for more details.

1681489254358.png


1681489288280.png


So below you can see that there is a match between the first 5 rows (non-highlighted in below image). The match should be connected between sheet IM_BARCOD, Column A and sheet UPCS Export Column B. It also needs to match between IM_BARCOD, Column C and sheet UPCS Export Column E.

The next 10 do NOT MATCH (highlighted) so those should look at the highest value in sheet IM_BARCOD, Column K for the corresponding range of numbers in Column A. In the example below Sheet IM_BARCOD has number 38518 in Column Awith the highest sequencial number ending in 22. So it should assign 23 through 32.

1681489649554.png


I didn't even attempt a VLOOKUP as I know I couldn't come close. Any help would be appreciated.
 
I did not type JadenR in the solution I sent, (and it is my impression excel should not have captured the local sheet name when people are using the mouse to select cells for formulas (which is what I did)). JadonR is what I named the worksheet I was working in. You could change that to 'UPCS Export'
in the formula but that is BAD excel for (why I'm so upset in my first parenthetical statement above)

try this in your cell H2 of your UPCS Export worksheet:

=INDEX(IM_BARCOD!$K$2:$K$64,MATCH(B3&E3,IM_BARCOD!$A$2:$A$64&IM_BARCOD!$C$2:$C$64,0))
=INDEX(IM_BARCOD!$K$2:$K$64,MATCH(B3&E3&F3,IM_BARCOD!$A$2:$A$64&IM_BARCOD!$C$2:$C$64&IM_BARCOD!$D$2:$D$64,0))

this should not have any JadonR sheet references:

mr excel questions 24.xlsm
ABCDEFGHIJK
1BARCODITEM_NOBARCOD_IDUNITDIM_1_UPRDIM_2_UPRDIM_3_UPRSEQ_NO
2=Table1[@UPC]=Table1[@[Style Number]]UPC#REF!=VLOOKUP(Table1[@[Color Code]],'Color Codes'!A$3:B$1000,2,FALSE)=Table1[@Size]=IF(Table1[@[Alt Size]]=0,"",Table1[@[Alt Size]])1triple match (added size lookup)
319296420454638518UPC0WHI-WhiteM123
419296420457738518UPC0WHI-WhiteL134
519296420460738518UPC0WHI-WhiteXL145
619296420463838518UPC0WHI-WhiteXXL156
719569978684438518UPC0BURD-Burl RedS#N/A6#N/A
JadonR
Cell Formulas
RangeFormula
D2D2='Color Codes'!C1
H3:H7H3=INDEX(IM_BARCOD!$K$2:$K$64,MATCH(B3&E3,IM_BARCOD!$A$2:$A$64&IM_BARCOD!$C$2:$C$64,0))
J3:J7J3=INDEX(IM_BARCOD!$K$2:$K$64,MATCH(B3&E3&F3,IM_BARCOD!$A$2:$A$64&IM_BARCOD!$C$2:$C$64&IM_BARCOD!$D$2:$D$64,0))
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hmm. Very strange. I copied the formula exactly and get a #VALUE! formula error. See below.

1681749974941.png
 
Upvote 0
Hmm. Very strange. I copied the formula exactly and get a #VALUE! formula error. See below.

View attachment 89875
make sure that the cell formats of columns
IM_BARCOD!A and 'UPCS Export'B matcch
IM_BARCOD!E and 'UPCS Export'C match
IM_BARCOD!D and 'UPCS Export'!F match
 
Upvote 0
I changed all cell formats in both tabs to "text". Error remains. Not sure why this is being so difficult for me...
 
Upvote 0
So, pressing F2 to edit the formula, then pressing CTRL+SHIFT+ENTER makes it work. Not sure why but that did it.

It changed the formula to:

{=INDEX(IM_BARCOD!$K$2:$K$64,MATCH(B3&E3&F3,IM_BARCOD!$A$2:$A$64&IM_BARCOD!$C$2:$C$64&IM_BARCOD!$D$2:$D$64,0))}
 
Upvote 0
So, pressing F2 to edit the formula, then pressing CTRL+SHIFT+ENTER makes it work. Not sure why but that did it.

It changed the formula to:

{=INDEX(IM_BARCOD!$K$2:$K$64,MATCH(B3&E3&F3,IM_BARCOD!$A$2:$A$64&IM_BARCOD!$C$2:$C$64&IM_BARCOD!$D$2:$D$64,0))}
that is odd. it is not an array formula function, and you are using 365 where CSE entry is not required for arrays.
all the braces mean is that it was entered using CSE.

And you should not change your data to text if you don't want to have text.

but, I'm happy you got it working.

Also, what happens if you hit F2 again and then hit enter?

Additionally, the formula i gave only goes to row 64.. you need to change the 64 to fit all of you column lengths.
 
Upvote 0
Thanks. I updated the formula to use 10000 instead of 64. However, there is one more question. If there is no match, it shows #N/A. Instead, I would like the formula to insert a number that will follow the sequence of numbers from the IM_BARCOD sheet that is next in line for that item number. In other words, below you can see in yellow the values that it should be filling in with.

CP Export Datasheet 1st t-shirt PO colors added.xlsm
ABCDEFGHI
1BARCODITEM_NOBARCOD_IDUNITDIM_1_UPRDIM_2_UPRDIM_3_UPRSEQ_NO
219296420451538518UPC0WHI-WhiteSGrid32
319296420454638518UPC0WHI-WhiteM3
419296420457738518UPC0WHI-WhiteL4
519296420460738518UPC0WHI-WhiteXL5
619296420463838518UPC0WHI-WhiteXXL6
719569978684438518UPC0BURD-Burl RedS#N/A62
819569978689938518UPC0BURD-Burl RedM#N/A63
919569978696738518UPC0BURD-Burl RedL#N/A64
1019569978705638518UPC0BURD-Burl RedXL#N/A65
1119569978714838518UPC0BURD-Burl RedXXL#N/A66
1219569979416038504UPC0DMGO-Dri MangoS#N/A
1319569979426938504UPC0DMGO-Dri MangoM#N/A
1419569979433738504UPC0DMGO-Dri MangoL#N/A
1519569979440538504UPC0DMGO-Dri MangoXL#N/A
UPCS Export
Cell Formulas
RangeFormula
A2A2=Table1[@UPC]
D2D2='Color Codes'!C1
E2E2=VLOOKUP(Table1[@[Color Code]],'Color Codes'!A$3:B$1000,2,FALSE)
F2F2=Table1[@Size]
G2G2=IF(Table1[@[Alt Size]]=0,"",Table1[@[Alt Size]])
B2:B15B2=Table1[@[Style Number]]
H2:H15H2=INDEX(IM_BARCOD!$K$2:$K$10000,MATCH(B2&E2&F2,IM_BARCOD!$A$2:$A$10000&IM_BARCOD!$C$2:$C$10000&IM_BARCOD!$D$2:$D$10000,0))
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A:ACell ValueduplicatestextNO


Here you can see where the range of sequence numbers stops on the IM_BARCOD sheet for this item number. So it should pick up from 61 by inserting 62 and so on for all rows that don't have a match.
1681828606758.png
 
Upvote 0
Thanks. I updated the formula to use 10000 instead of 64. However, there is one more question. If there is no match, it shows #N/A. Instead, I would like the formula to insert a number that will follow the sequence of numbers from the IM_BARCOD sheet that is next in line for that item number. In other words, below you can see in yellow the values that it should be filling in with.

CP Export Datasheet 1st t-shirt PO colors added.xlsm
ABCDEFGHI
1BARCODITEM_NOBARCOD_IDUNITDIM_1_UPRDIM_2_UPRDIM_3_UPRSEQ_NO
219296420451538518UPC0WHI-WhiteSGrid32
319296420454638518UPC0WHI-WhiteM3
419296420457738518UPC0WHI-WhiteL4
519296420460738518UPC0WHI-WhiteXL5
619296420463838518UPC0WHI-WhiteXXL6
719569978684438518UPC0BURD-Burl RedS#N/A62
819569978689938518UPC0BURD-Burl RedM#N/A63
919569978696738518UPC0BURD-Burl RedL#N/A64
1019569978705638518UPC0BURD-Burl RedXL#N/A65
1119569978714838518UPC0BURD-Burl RedXXL#N/A66
1219569979416038504UPC0DMGO-Dri MangoS#N/A
1319569979426938504UPC0DMGO-Dri MangoM#N/A
1419569979433738504UPC0DMGO-Dri MangoL#N/A
1519569979440538504UPC0DMGO-Dri MangoXL#N/A
UPCS Export
Cell Formulas
RangeFormula
A2A2=Table1[@UPC]
D2D2='Color Codes'!C1
E2E2=VLOOKUP(Table1[@[Color Code]],'Color Codes'!A$3:B$1000,2,FALSE)
F2F2=Table1[@Size]
G2G2=IF(Table1[@[Alt Size]]=0,"",Table1[@[Alt Size]])
B2:B15B2=Table1[@[Style Number]]
H2:H15H2=INDEX(IM_BARCOD!$K$2:$K$10000,MATCH(B2&E2&F2,IM_BARCOD!$A$2:$A$10000&IM_BARCOD!$C$2:$C$10000&IM_BARCOD!$D$2:$D$10000,0))
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A:ACell ValueduplicatestextNO


Here you can see where the range of sequence numbers stops on the IM_BARCOD sheet for this item number. So it should pick up from 61 by inserting 62 and so on for all rows that don't have a match.
View attachment 89946
wrap the formula in an "IFERROR" function, with the 3rd argument being the cell address above + 1. So, if in cell H2:
=IFERROR('the formula', N(H1)+1)

Note: if cell H1 is non numeric, the N() function changes non numeric values to 0.
 
Upvote 0
wrap the formula in an "IFERROR" function, with the 3rd argument being the cell address above + 1. So, if in cell H2:
=IFERROR('the formula', N(H1)+1)

Note: if cell H1 is non numeric, the N() function changes non numeric values to 0.
i just realized you don't want the cell above plus 1.

Your example has a conundrum. How would you know what the record above matches too? In the example, how I am to know to look for 38518, WAVY BLUE XXL to find the number to add 1 to? (Sorry if misspelled, again, images are not helpful).
 
Upvote 0
Sorry for the images. Couldn't it be some additional nested match that could look at the item no and then the highest seq no for that item no? Then increment by 1. But it sounds like that may be out of reach?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,876
Messages
6,127,482
Members
449,385
Latest member
KMGLarson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top