Show different values based on the result using nested IF and VLOOKUP formula

purevtsagaan

New Member
Joined
Mar 2, 2014
Messages
4
A
B
C
1
clothes
transportation
drinks
2
pants
car
coffee
3
shirt
train
tea
4
sweater
bicycle
juice
5
tie
plane
milk

<tbody>
</tbody>










Hello everyone,
I have been trying so had to make this work.
I want to return "category 1" if the text is found in column A, "category 2"if it is found n column b, "category 3" If it is found in column c, if not found in any column "category 4".
Please help here is sheet and formula, thanks

=IF(SUBSTITUTE(A1, "-", "")=VLOOKUP(SUBSTITUTE(A1,"-",""),sheet1!$A$2:$A$6,1,FALSE),
"CATEGORY 1",
IF(SUBSTITUTE(A1, "-", "")=VLOOKUP(SUBSTITUTE(A1, "-", ""),sheet1!$B$2:$B$6,2,FALSE),
"CATEGORY 2",
IF(SUBSTITUTE(A1, "-", "")=VLOOKUP(SUBSTITUTE(A1, "-", ""),sheet1!$C$2:$C$6,3,FALSE),
"CATEGORY 3",
"Category 4")
)
)

PS: first if statement works but 2nd and 3rd ones do not. Please help me by fixing. Thanks!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Sorry, the text t test is here,
BICYCLE
soc-ks
PA-NTS
pla-ne
ca-r
milk
juice
tea
cof-fee

<tbody>
</tbody>

So I want the function to sort these texts into 4 different categories based on their types.
 
Upvote 0
yup, the hyphen exists.
the substitute removes he hyphens.

clothestransportationdrinks#List#Category
pantscarcoffeeBICYCLE2
shirttrainteasoc-ks4
sweaterbicyclejuicePA-NTS1
tieplanemilkpla-ne2
ca-r2
milk3
juice3
tea3
cof-fee3

<tbody>
</tbody>

H2, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=MIN(4,MIN(IF($A$2:$C$5=SUBSTITUTE(G2,"-",""),
  COLUMN($A$2:$C$5)-MIN(COLUMN($A$2:$C$5))+1,9.99E+307)))
 
Upvote 0
Aladin thank you so much it works,
But could you explain how above code works step by step if it is not too much.
I am in debt to you.
 
Upvote 0
Aladin thank you so much it works,

You are welcome.

But could you explain how above code works step by step if it is not too much.
I am in debt to you.

The IF bit in:

=MIN(4,MIN(IF($A$2:$C$5=SUBSTITUTE(G2,"-",""),COLUMN($A$2:$C$5)-MIN(COLUMN($A$2:$C$5))+1,9.99E+307)))

returns the relative column number when the data equals the #List# value of interest (hyphens removed if any), otherwise the Excel's big number. That is, the formula maps the relative column number one to one to the categories as you specified.

The valuation occurs successively as follows:

==>

=MIN(4,MIN(IF({FALSE,FALSE,FALSE;FALSE,FALSE,FALSE;FALSE,TRUE,FALSE;FALSE,FALSE,FALSE},COLUMN($A$2:$C$5)-MIN(COLUMN($A$2:$C$5))+1,9.99E+307)))

==>

=MIN(4,MIN(IF({FALSE,FALSE,FALSE;FALSE,FALSE,FALSE;FALSE,TRUE,FALSE;FALSE,FALSE,FALSE},{1,2,3},9.99E+307)))

==> (note the big number for each FALSE)

=MIN(4,MIN({9.99E+307,9.99E+307,9.99E+307;9.99E+307,9.99E+307,9.99E+307;9.99E+307,2,9.99E+307;9.99E+307,9.99E+307,9.99E+307}))

==>

=MIN(4,2)

==>

2

which is the desired outcome for BICYCLE.

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,216,087
Messages
6,128,740
Members
449,466
Latest member
Peter Juhnke

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