Need quick help for IIF function. Returning results of a certain format

Aero11

New Member
Joined
Sep 16, 2011
Messages
34
Hello everyone. I have been trying to figure out queries for a little while now at work, and usually I can find my answer by myself. However, I have been unable to find my answer this time, and I'm hoping to get some help here.

What I am trying to do is to create an IIF function that returns results in a certain format. I'm sure this can be done, but I don't think I am using the right commands. Specifically, I want the query to return the result "Commercial" if the search result is in the format 12-34-56, and return "Military" if the number is in any other format.

Something like...

IIF((Wo_headc.ATA_MAN_NBR) LIKE "**-**-**",'Commercial','Military')

??

Please help. Thanks! This is driving me crazy!
 
Change the ? to %, I think.

We're getting closer now! It is separating the results, but it isn't following the exact format that I requested.

For example, "15A1-2-38-3-1" still returns "Commercial". Other results like "39-27972" are returning "Military".

I think it is looking for any number that has 2 "-"s in it and returning "Commercial". It isn't looking at the location of the "-"s
 
Last edited:
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Is there any way to make the "Like" command stricter? It's working, but it is including results that I don't want it to.
 
Upvote 0
Hopefully somebody is still willing to help,

It appears that the LIKE '%%-%%-%%' is returning the same results as LIKE '%-%-%'. So it is not counting the number of "%"s that I use. "%" looks for any number of digits.

Is there to way to program this so that it counts a specific number of digits in the format?

Thanks again.
 
Upvote 0
The problem is that the wildcards are not being counted in the query. Whether I use one or 10, it doesn't matter.

Is there a way to return results where a "-" is the 3rd, and 5th character in every result? That will probably achieve the same result.
 
Upvote 0
I heard something about a substring argument?

Could I implement this substring into my iif statement? If it returned results where the 3rd and 5th character is a "-", I should be getting the correct results.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

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