Wildcard and Nested IF Statements

madkinson

Board Regular
Joined
Dec 17, 2004
Messages
113
Office Version
  1. 365
Platform
  1. Windows
In Excel 2013, I'm trying to create a nested IF statement using wildcards. I have data similar to the following:

PC Unit Account
CMCPX 21002400 GOOD
CMOPX 21002400 BAD
CMOPX 70021160 GOOD
CMCPX 70021178 BAD
CMOPX 70021186 GOOD
CMCPX 21001599 GOOD
CMOPX 21003601 BAD

When "PC Unit" = "CMCPX", I want the 3rd column to say "Good" whenever "Account" (col B) is equal to "2100*"
When "PC Unit" = "CMOPX", I want the 3rd column to say "Good" whenever "Account" is equal to "7002*"
Any other combination of values should be marked as "Bad".
There can only be either one of the other listed values in col A.
Since there are multiple valid ACCOUNT values, I tried to use a"*" as a wildcard.

Try as I might, I cannot get a valid IF statement to work. I thought about using an INDEX/MATCH, but I don't know how to put the values into the INDEX. I've always referred to ranges instead.

I really would appreciate some assistance on this as the spreadsheet has about 55,000 rows and manually spotting bad values takes a REALLY long time.

Thanking you in advance,
Mark
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi,

How about this in Cell C2 and copied down:

Code:
=IF(AND(A2="CMCPX",VALUE(LEFT(B2,4))=2100),"GOOD",IF(AND(A2="CMOPX",VALUE(LEFT(B2,4))=7002),"GOOD","BAD"))

If you have that many rows, you may want to leave the "GOOD" out and replace it with a blank "" so that just the "BAD" stand out when you scan the column...

igold
 
Last edited:
Upvote 0
Using your sample data:
A
B
1
PC Unit​
Account​
2
CMCPX​
21002400​
3
CMOPX​
21002400​
4
CMOPX​
70021160​
5
CMCPX​
70021178​
6
CMOPX​
70021186​
7
CMCPX​
21001599​
8
CMOPX​
21003601​

This formula, copied down, returns GOOD if either combination applies, otherwise BAD
Code:
C2: =IF(SUMPRODUCT(COUNTIFS(A2,{"CMCPX";"CMOPX"},B2,{"2100*";"7002*"})),"GOOD","BAD")

Alternatively, you could put your criteria in a separate range:
E
F
1
PC Unit​
Account​
2
CMCPX​
2100*​
3
CMOPX​
7002*​

and use this formula
Code:
C2: =IF(SUMPRODUCT(COUNTIFS(A2,$E$2:$E$3,B2,$F$2:$F$3)),"GOOD","BAD")

For your data, these are the results, using either formula:
A
B
C
1
PC Unit​
Account​
2
CMCPX​
21002400​
GOOD​
3
CMOPX​
21002400​
BAD​
4
CMOPX​
70021160​
GOOD​
5
CMCPX​
70021178​
BAD​
6
CMOPX​
70021186​
GOOD​
7
CMCPX​
21001599​
GOOD​
8
CMOPX​
21003601​
BAD​
Is that something you can work with?
 
Upvote 0
Hey Ron,

First I want to thank you very much.

On a MS community site you posted a solution to the problem when all un-formatted cells in a Spreadsheet suddenly default to a date format. That problem had been bugging me for months on a spreadsheet that I did not want to re-create.

For this post, in an effort to work with different solutions to the same problem I tried yours out. My results are coming back as all False or "Bad". I copied it twice with the same results. Any thoughts...

Regards,

igold
 
Upvote 0
I think the accounts need to be text, not numeric, for the wildcard to engage properly.
Are your account values text?
 
Upvote 0
Actually, I tried both ways with the same result.

I guess one way to know would be to see what the OP comes up with...
 
Last edited:
Upvote 0
Something must be different....I copied the example and the formulas directly from my Excel workbook.

Can you copy the example from my post, including the formulas, and see if the example returns the correct values on your computer?
 
Upvote 0
Ron:

Your first solution works so I'm going with it as I don't want to create a separate range. Thanks so much for both. Now I have to sit down and work through it so I can understand for the next time I need it.

IGold, thanks too for your solution.
 
Upvote 0
I did have to change the cell format to TEXT on the column for ACCOUNT for it to work.
 
Upvote 0
OK, I just copied your post from the top section and the bottom section (two separate sheets) of the post, then copied your formula into C2 and it is still coming back as all false. I am pretty sure I have not copied wrong or done something easy (read as stupid), it just does not want to return anything but false...
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

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