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!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Not sure, but did you try changing the *'s to #'s?

Thanks for the suggestion.

I got a little closer. The Query is accepting the following

IIF(ATA_MAN_NBR) LIKE '**-**-**','Commercial','Military)

But it returned EVERY result as "Military". Even the ones that fit the format did not return the correct result.

I tried using #'s instead of *'s and it did the same thing.
 
Upvote 0
Try

IIF(ATA_MAN_NBR) LIKE '??-??-??','Commercial','Military)


Still returning "Military" for every result.

I think the LIKE function is not looking at the format of the expression, but rather the numbers themselves. Maybe I should not be using the LIKE function? I don't know of any others, though.
 
Upvote 0
Ah, you did't say what ATA_MAN_NBR was. If it is a cell reference try like this

=IIf(ATA_MAN_NBR.NumberFormat like ...
 
Upvote 0
Ah, you did't say what ATA_MAN_NBR was. If it is a cell reference try like this

=IIf(ATA_MAN_NBR.NumberFormat like ...

Sorry, I didn't explain this correctly.

The ATA_MAN_NBR column contains manual numbers. The Commercial manual numbers always have the format 12-34-56. They are always numbers. The Military manuals can be anything else, including 12A-3F-333, etc. So it's not strictly numbers.

I tried

IIF((ATA_MAN_NBR.NumberFormat) Like '??-??-??','Commercial','Military')

but it returned "Table or Alias not found"
 
Upvote 0
I'm still not sure what ATA_MAN_NBR is.

Try like this

=IIF(Range("A1").NumberFormat Like '??-??-??','Commercial','Military')
 
Upvote 0
I'm still not sure what ATA_MAN_NBR is.

Try like this

=IIF(Range("A1").NumberFormat Like '??-??-??','Commercial','Military')

I should have mentioned that I am not using Access, I am using the Microsoft Query tool that comes with Excel.

ATA_MAN_NBR is just just a column within one of the tables I am working from.
 
Upvote 0
I should have mentioned that I am not using Access, I am using the Microsoft Query tool that comes with Excel.

ATA_MAN_NBR is just just a column within one of the tables I am working from.

Change the ? to %, I think.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
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