IIf Syntax ( how to read and understand)

yantan2006

New Member
Joined
Jun 30, 2011
Messages
27
Good day to all,

I am novice to formulas, functions. i couldn't figure out how to read and understand syntaxes.

I understand "is null" find's blank entry and IIf works similar to "if" function...

Customer Name: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[Company],[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name]))


1. could you please help me what does this formula syntax tells?

2. actually please tell me how to read and understand a lengthy syntax?

any web link, book, tutorial you recommend on understanding syntaxes will be appreciated.

Thanks in advance
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
IIf function consists of 3 parts separated with comma as below:
Rich (BB code):
IIf(comparison_here, this_returns_if_comparison_true, this_returns_if_comparison_false);

Sample: returns true since 1 = 1
IIf(1=1, "true", "false")

More practical sample:returns message according to Role field value
IIf([Role]="Admin", "Welcome Admin", "Welcome User")

Your sample: consist of insider IIfs. You should see all parts separately, so it makes more sense.
Rich (BB code):
IIf(    
    IsNull([Last Name]),
    IIf(
        IsNull([First Name]), 
        [Company], 
        [First Name]
        ),
    IIf(
        IsNull([First Name]), 
        [Last Name], 
        [First Name] & " " & [Last Name]
    )
)


Outer IIf looks if LastName is null or not and executes inner IIfs.

Rich (BB code):
It Looks for LastName is null or not null
    If LastName is null then it looks if FirstName is null or not. 
        If FirstName is null then it returns Company
        Else it returns FirstName
    If LastName is not null then it looks if FirstName is null or not
        If FirstName is null then it returns LastName
        Else it returns concatenation of FirstName and LastName

Very well explained here as well.

Hope it helps.
 
Upvote 0
I hearty thank you and appreciate your efforts for explaining by breaking it in parts.

May God bless you......

Thank you very much
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

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