Help using AND OR in IIF statement

oliviar

Board Regular
Joined
Sep 12, 2010
Messages
184
Hi Guys,
I want to do this:
iif([POP] = 1 OR 2 OR 3,[POP]+1,[POP])

When I wrote it like that, it just added 1 to everything - even if the POP wasn't 1,2,or 3.

What am I doing wrong?
:(
 
Another way of writing your incorrect statement is:
Code:
x = 5
If Not x = 1 Then
    If 2 Then
        If 3 Then
            x = 5 + 1
        Else
            x
        End If
    End If
End If

Another way of writing the correct statement is:
Code:
x = 5
If Not x = 1 Then
    If Not x = 2 Then
        If Not x = 3 Then
            x = 5 + 1
        Else
            x
        End If
    End If
End If

If using VBA then yes, but the other works in a query or control source where this code wouldn't.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I see... because I have not asked the if 2 or if 3 to compare against anything, its just going 2? and 3? and 2 or 3 on their own are just 2 or 3. they can't be false.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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