Formula to search range by two criteria or different two criteria, and if not found then search different range using same criteria(s)

DrMrsStark

New Member
Joined
Jun 28, 2021
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
Hello Excel Wizards! - Longtime reader, first time writer.

So I have a situation that I feel is completely do-able, because I've been able to successfully write one part of the formula to achieve my results, but cannot for the life of me get the entire formula right.
I apologize in advance for the XL mini-sheet samples.

All my data is separated into two .XLSM workbooks - One workbook with the "Data_Sample" table in it (the real file ranges from $A$2:$X$*is continuously growing in length as more data is added*), and one with the "Reference_Sample" table (the real file here ranges from $A$2:$DD$163 at this time, but more references might be added later).
I decided to separate the two sets of data into completely separate Workbooks because compiling all the data in one Workbook and on different Sheets was causing my device to run incredibly hot and Excel itself would freeze and crash, but also because I don't necessarily need the "Reference_Sample" table up or open when actively working on and adding data to the "Data_Sample" table.​


What I'm trying to do is in [RANK] (a.k.a. E2) of the "Data_Sample" table, search [BRAND] (a.k.a. G2) AND [COLOR(S)] (a.k.a. J2), OR search [BRAND] (a.k.a. G2) AND [COLOR(S) NAME] (a.k.a. S2) in the "References_Sample" table, and if there's a match then return the single value in the corresponding [COLOR #*** MATCH] (a.k.a. H2, L2, or P2) columns.


✱ But the trick(s) is the [BRAND] (a.k.a. G2) in the "Data_Sample" table absolutely has to match the [BRAND] (a.k.a. A2) in the "Reference_Sample" table, regardless what the other two criteria are.​
✱ Also the possible entries for [COLOR(S) NAME] (a.k.a. S2) of the "Data_Sample" table, and [COLOR #*** NAME] (a.k.a. G2, K2, or O2) in the "References_Sample" table tend to repeat as the Color Names for different Brands - This is also true for the possible entries for [COLOR(S)] (a.k.a. J2) in the "Data_Sample" table and [COLOR #*** NUMBER] (a.k.a. F2, J2, or N2) in the "References_Sample" table.​

✱ Ideally I would like for the formula to first search by [COLOR(S)] (a.k.a. J2) criteria, then if not found search the same set of data by the [COLOR(S) NAME] (a.k.a. S2) criteria... of course given the Brand is a match.​

✱ If possible I would like to avoid using helper columns, and my VBA experience is only YouTube deep.​
Also I've been mentally approaching the problem as "search Color #1 cell $E$2:$H$163 range for match, and if neither condition is met, then move on to search Color #2 cell $I$2:$L$163 range for match, and if neither condition is met, then continue on to search Color #3 cell $M$2:$P$163 range for match, etc. until the last Color #26 cell $DA$2:$DD$163 range" - But I'm starting to think this might be the source of my troubles!
So far I've been able to successfully return values if the [BRAND] (a.k.a. G2) AND [COLOR(S)] (a.k.a. J2) has a match in the "References_Sample" table Color #1 cell range, but not with adding the the OR [BRAND] (a.k.a. G2) AND [COLOR(S) NAME] (a.k.a. S2) logic, or using variations of nested AND, OR, INDEX, MATCH, XLOOKUP, IFERROR, and OFFSET, such as:
  1. nested IFERROR/INDEX/IFERROR/MATCH/OR/OFFSET/INDEX/IFERROR/MATCH/OR
  2. nested XLOOKUP/OR/OFFSET/XLOOKUP
  3. nested XLOOKUP/OR/XLOOKUP
  4. nested XLOOKUP/XLOOKUP
  5. nested XLOOKUP/XLOOKUP/OFFSET/OFFSET
  6. nested XLOOKUP/IFERROR/XLOOKUP/OFFSET/IFERROR/OFFSET
  7. nested IFERROR/INDEX/MATCH/OFFSET/XMATCH
  8. nested XLOOKUP/OFFSET/OR/OFFSET
  9. nested IFERROR/OR/XLOOKUP/XLOOKUP/OFFSET/OR/XLOOKUP/XLOOKUP
  10. nested OR/XLOOKUP/XLOOKUP
  11. nested XLOOKUP/OFFSET/XLOOKUP
  12. nested XLOOKUP/OR/XLOOKUP/OFFSET/OR/OFFSET


WORKS:
Excel Formula:
=INDEX([Reference_Sample_Workbook.xlsm]Reference_Sample!$H$2:$H$163,MATCH(G2&J2,[Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163&[Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163,0))

NO BUENO:
Excel Formula:
=INDEX([Reference_Sample_Workbook.xlsm]Reference_Sample!$H$2:$H$163,OR(MATCH(G2&J2,[Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163&[Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163,0),MATCH(G2&S2,[Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163&[Reference_Sample_Workbook.xlsm]Reference_Sample!$G$2:$G$163,0)))



Again, to me what I'm trying to do seems feasible and not overly complicated, but I'm still learning when to use the appropriate functions and am really hoping that this is just a case of using the wrong function.
But nonetheless I welcome any and all suggestions and comments!!

-DrMrsStark


Data Table
Data_Sample-Workbook.xlsm
ABCDEFGHIJKLMNOPQRS
1RATINGPROMATCHREADYRANKNOTE(S)BRANDMETHODCOLOR TYPECOLOR(S)CONTAIN(S)WIDTHLENGTHGRAMSPRICEPRICE/GRAMPRO. PRICEPRO. PRICE/GRAMCOLOR(S) NAME
21Brand 312/613150 to 6022220
3#N/ABrand 34/60150 to 6022220
4#N/ABrand 6P4/27320150
51Brand 6RP3/6/12320150
6#N/ABrand 74/223332263
72Brand 74/123332263
8#N/ABrand 76/603332263
90Brand 912/60013622.5160Color 12/Color 111
10#N/ABrand 94/61313622.5160Color 4/Color 10
11#N/ABrand 912/6013622.5160Color 12/Color 11
Data_Sample
Cell Formulas
RangeFormula
E2:E11E2=INDEX([Reference_Sample_Workbook.xlsm]Reference_Sample!$H$2:$H$163,MATCH(G2&J2,[Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163&[Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163,0))
L6:L8L6=11+11+11
L9:L11L9=36




Reference Table
Reference_Sample_Workbook.xlsm
ABCDEFGHIJKLMNOP
1BRANDACCOUNT STATUSRATINGCOLOR REVIEWCOLOR #1 TYPECOLOR #1 NUMBERCOLOR #1 NAMECOLOR #1 MATCHCOLOR #2 TYPECOLOR #2 NUMBERCOLOR #2 NAMECOLOR #2 MATCHCOLOR #3 TYPECOLOR #3 NUMBERCOLOR #3 NAMECOLOR #3 MATCH
2Brand 1-3
3Brand 234Color 42
4Brand 3312/613Color 12/Color 1014/60Color 4/Color 1126/60Color 6/Color 112
5Brand 4-3
6Brand 5-3
7Brand 63RP3/6/12Color 3/Color 121RP6/18/613Color 6/Color 100P8/60Color 8/Color 110
8Brand 734/1224/2226/601
9Brand 8-3
10Brand 9312/600Color 12/Color 111012/60Color 12/Color 1111B/60Color 1/Color 113
Reference_Sample
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I haven't read through your entire post, just went straight to the 'almost' formula at the bottom and added 4 characters to it.

Rich (BB code):
=INDEX([Reference_Sample_Workbook.xlsm]Reference_Sample!$H$2:$H$163,IFERROR(MATCH(G2&J2,[Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163&[Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163,0),MATCH(G2&S2,[Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163&[Reference_Sample_Workbook.xlsm]Reference_Sample!$G$2:$G$163,0)))

Another method for older versions of excel (2010 or newer). The 2 formulas below should be more efficient that using MATCH with concatenated arrays.

Excel Formula:
=INDEX([Reference_Sample_Workbook.xlsm]Reference_Sample!$H:$H,AGGREGATE(15,6,ROW([Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163)/([Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163=G2)/(([Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163=J2)+([Reference_Sample_Workbook.xlsm]Reference_Sample!$G$2:$G$163=S2)),1))

And one for office 365 (note that this will not work if the reference sample workbook is closed)

Excel Formula:
=FILTER([Reference_Sample_Workbook.xlsm]Reference_Sample!$H$2:$H$163([Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163=G2)*(([Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163=J2)+([Reference_Sample_Workbook.xlsm]Reference_Sample!$G$2:$G$163=S2)),"Not Found")
 
Upvote 0
I haven't read through your entire post, just went straight to the 'almost' formula at the bottom and added 4 characters to it.

Rich (BB code):
=INDEX([Reference_Sample_Workbook.xlsm]Reference_Sample!$H$2:$H$163,IFERROR(MATCH(G2&J2,[Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163&[Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163,0),MATCH(G2&S2,[Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163&[Reference_Sample_Workbook.xlsm]Reference_Sample!$G$2:$G$163,0)))

Another method for older versions of excel (2010 or newer). The 2 formulas below should be more efficient that using MATCH with concatenated arrays.

Excel Formula:
=INDEX([Reference_Sample_Workbook.xlsm]Reference_Sample!$H:$H,AGGREGATE(15,6,ROW([Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163)/([Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163=G2)/(([Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163=J2)+([Reference_Sample_Workbook.xlsm]Reference_Sample!$G$2:$G$163=S2)),1))

And one for office 365 (note that this will not work if the reference sample workbook is closed)

Excel Formula:
=FILTER([Reference_Sample_Workbook.xlsm]Reference_Sample!$H$2:$H$163([Reference_Sample_Workbook.xlsm]Reference_Sample!$A$2:$A$163=G2)*(([Reference_Sample_Workbook.xlsm]Reference_Sample!$F$2:$F$163=J2)+([Reference_Sample_Workbook.xlsm]Reference_Sample!$G$2:$G$163=S2)),"Not Found")


Hi jasonb75 and thank you for your reply! Unfortunately none of the formulas you provided solved the issue I'm having.
 
Upvote 0
I missed part of what was required. It might be possible, but the reference sample is badly laid out. I would want to see the correct expected results in the mini sheet rather than just attempted formulas that don't work before attempting anything else.
 
Upvote 0
I missed part of what was required. It might be possible, but the reference sample is badly laid out. I would want to see the correct expected results in the mini sheet rather than just attempted formulas that don't work before attempting anything else.


I absolutely agree, the reference sample isn't very friendly at all

I guess a better way to describe the goal is to match the brand in both sheets, then search columns in chunks (i.e. columns E:H, I:L, M:P, etc) and match either the color number or color name in each chunk, then return the value in the last column of the chunk searched.. so the actual return value will change based on which column had the match. For example, if the match was a color name, the return value would come from the column immediately to the right, and if the match was a color number, the return value would come from the column x1 column over to the right.
 
Upvote 0
This is the only thing that I've been able to come up with that looks as if it is anywhere close. I've used the LET function to shorten the formula a little but it can be done without that if you don't have it yet.
Reference Data file.xlsx
EFGHIJKLMNOPQRS
1RANKNOTE(S)BRANDMETHODCOLOR TYPECOLOR(S)CONTAIN(S)WIDTHLENGTHGRAMSPRICEPRICE/GRAMPRO. PRICEPRO. PRICE/GRAMCOLOR(S) NAME
21Brand 312/613150 to 6022220
32Brand 3Apr-60150 to 6022220
4No matchBrand 6P4/27320150
51Brand 6RP3/6/12320150
62Brand 7Apr-223332263
72Brand 704-Dec3332263
81Brand 7Jun-603332263
90Brand 912/60013622.5160Color 12/Color 111
10No matchBrand 94/61313622.5160Color 4/Color 10
111Brand 9Dec-6013622.5160Color 12/Color 11
Sheet1
Cell Formulas
RangeFormula
E2:E11E2=LET(row,MATCH(G2,[Reference_Sample_workbook.xlsm]Reference_Sample!$A$2:$A$10,0),result,INDEX([Reference_Sample_workbook.xlsm]Reference_Sample!$H$2:$P$10,row,0),num,INDEX([Reference_Sample_workbook.xlsm]Reference_Sample!$F$2:$N$10,row,0),name,INDEX([Reference_Sample_workbook.xlsm]Reference_Sample!$G$2:$O$10,row,0),FILTER(result,(num=J2)+IF(S2<>"",name=S2),"No match"))
L6:L8L6=11+11+11
L9:L11L9=36
 
Upvote 0

Forum statistics

Threads
1,215,477
Messages
6,125,037
Members
449,205
Latest member
Eggy66

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