Lookup value within range

arnabmit

New Member
Joined
Mar 28, 2009
Messages
27
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I have data table which has [Sub-Cat ID].

Another mapping table has [Category ID] [Category Name] [Sub-Cat Start] [Sub-Cat End]

I want to insert a new column in the data table which will lookup the corresponding [Category ID] for each [Sub-Cat ID] where [Sub-Cat ID] >= [Sub-Cat Start] AND [Sub-Cat ID] < [Sub-Cat End]

Please help, I'm lost!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
So am I. Could we have some sample data and expected results with XL2BB and explain again in relation to the sample data?

Thanks for replying. XL2BB is blocked by Excel. Here are some screenshots instead.

If the value of column A falls between columns G and H, then corresponding value from column E should be returned

1692983701757.png


Expected output is as below:

1692983841187.png
 
Upvote 0
If the col A value will always be in one of the sub-categories in the second table and the second table sub-categories are in ascending order like your sample then try ..

arnabmit.xlsm
ABCDEFGH
1
2Sub-Cat IDNameCategory IDCategory IDCategory NameSub-Cat StartSub-Cat End
31001a10001000AB10011010
41003b10001100BC11011110
51005c10001230CD12311239
61009d1000
71101e1100
81102f1100
91107g1100
101234h1230
111237i1230
Sheet1
Cell Formulas
RangeFormula
C3:C11C3=LOOKUP([@[Sub-Cat ID]],Table2[Sub-Cat Start],Table2[Category ID])


If the col A value may not be in any sub-category and/or the second table sub-categories may not all be in ascending order then a couple of options to try depending on which of your listed versions this needs to work in.

arnabmit.xlsm
ABCDEFGHI
1
2Sub-Cat IDNameCategory IDCategory ID2Category IDCategory NameSub-Cat StartSub-Cat End
31001a100010001000AB10011010
41003b100010001230CD12311239
51005c100010001100BC11011110
61009d10001000
71101e11001100
81102f11001100
91107g11001100
101234h12301230
111237i12301230
121120jNot foundNot found
13
Sheet1
Cell Formulas
RangeFormula
C3:C12C3=FILTER(Table2[Category ID],(Table2[Sub-Cat Start]<=[@[Sub-Cat ID]])*(Table2[Sub-Cat End]>=[@[Sub-Cat ID]]),"Not found")
D3:D12D3=IFERROR(INDEX(Table2[Category ID],AGGREGATE(15,6,(ROW(Table2[Category ID])-ROW(Table2[#Headers]))/((Table2[Sub-Cat Start]<=[@[Sub-Cat ID]])*(Table2[Sub-Cat End]>=[@[Sub-Cat ID]])),1)),"Not found")
 
Upvote 1
Solution
If the col A value will always be in one of the sub-categories in the second table and the second table sub-categories are in ascending order like your sample then try ..

arnabmit.xlsm
ABCDEFGH
1
2Sub-Cat IDNameCategory IDCategory IDCategory NameSub-Cat StartSub-Cat End
31001a10001000AB10011010
41003b10001100BC11011110
51005c10001230CD12311239
61009d1000
71101e1100
81102f1100
91107g1100
101234h1230
111237i1230
Sheet1
Cell Formulas
RangeFormula
C3:C11C3=LOOKUP([@[Sub-Cat ID]],Table2[Sub-Cat Start],Table2[Category ID])


If the col A value may not be in any sub-category and/or the second table sub-categories may not all be in ascending order then a couple of options to try depending on which of your listed versions this needs to work in.

arnabmit.xlsm
ABCDEFGHI
1
2Sub-Cat IDNameCategory IDCategory ID2Category IDCategory NameSub-Cat StartSub-Cat End
31001a100010001000AB10011010
41003b100010001230CD12311239
51005c100010001100BC11011110
61009d10001000
71101e11001100
81102f11001100
91107g11001100
101234h12301230
111237i12301230
121120jNot foundNot found
13
Sheet1
Cell Formulas
RangeFormula
C3:C12C3=FILTER(Table2[Category ID],(Table2[Sub-Cat Start]<=[@[Sub-Cat ID]])*(Table2[Sub-Cat End]>=[@[Sub-Cat ID]]),"Not found")
D3:D12D3=IFERROR(INDEX(Table2[Category ID],AGGREGATE(15,6,(ROW(Table2[Category ID])-ROW(Table2[#Headers]))/((Table2[Sub-Cat Start]<=[@[Sub-Cat ID]])*(Table2[Sub-Cat End]>=[@[Sub-Cat ID]])),1)),"Not found")

Thank you so much! This is truly helpful.
 
Upvote 0
You're welcome. Glad it helped. Thanks for the follow-up. :)

Don't forget to check out @Fluff's link re XL2BB if you have further questions. You will generally get much faster/better suggestions as most helpers are not that keen on manually typing out data to test with. ;)
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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