Nested IF and Match issue

andrewlau2881

New Member
Joined
Oct 20, 2023
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Excel Formula:
=IF(MATCH(K2,A3:A33,0),1,IF((MATCH(K2,B3:B33,0)),2,""))

I would like to search through columns A and B to match a name.

If that name is found then I would like to return 1 if it is in column A and 2 if it is in column B.

It returns a 1 if it is in column A. However, if it is in column B I get N/A. I have used very similar IF statments before with success but cannot get my head around why this one won't work.

All help appreciated.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
If it's not in column A, the first MATCH will return #N/A, and hence the formula will return #N/A.

One way to fix it: =IF(ISNUMBER(MATCH(K2,A3:A33,0)),1,IF(ISNUMBER(MATCH(K2,B3:B33,0)),2,""))

Or with Excel 365, you could say: =LET(m,MIN(IF(A2:B33=K2,{1,2})),IF(m=0,"",m))
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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