OR in IF

T

T2net

Do you know a way to include several conditions to one IFstep in VBA,
ie

If condition1 OR condition2 OR condition3 then action1
without using my current unelegant and heavy:

If condition1 then action1
If condition 2 then action1
If condition 3 then action1


I am sure the trick is easy..so easy that I cannot find it!

Thanks in advance for your help,

T2net
 
O

OssieMac

The or is a function like this with each condition separated by a comma:-

=IF(OR(A4=1,B4=2,C4=3),"Yes","No")
 
S

Stefi

You've answered your own question:
If condition1 OR condition2 OR condition3 then action1

IS the solution. Try it!

Regards,
Stefi



„T2net†ezt írta:
 
D

David Biddulph

Are you sure that's VBA?
--
David Biddulph

OssieMac said:
The or is a function like this with each condition separated by a comma:-

=IF(OR(A4=1,B4=2,C4=3),"Yes","No")
 
A

Arvi Laanemets

The shortened syntax (If <LogicalCondition> Then response) looks like
reasonable, but I have several times had problems with it - so I prefer the
full syntax:

If Condition Then
Action
[ElseIf ElseCondition
ElseIfAction]
[Else
ElseAction]
End If

In your case Condition is =condition1 Or condition2 Or condition3
 
O

OssieMac

Thanks David. The question came up under Worksheet Functions on the Microsoft
Forum and I did not read it properly and missed the VBA at the end of the
question and thought that a worksheet function was required.
 
T

T2net

You've answered your own question:


IS the solution. Try it!

Regards,
Stefi

"T2net" ezt írta:









- Afficher le texte des messages précédents -

I knew it!!
I had certainly a error mixed with the or last time I tried...

Sorry for disturbing with my stupid question!

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top