Thread: or operator
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default or operator

On Sat, 20 Jan 2007 07:11:27 -0600, Ed wrote:

What would be the correct coding syntax for the following:

If a = x then
(instructions)
or If b = x then
(instructions)
or If c = x then
(instructions)
or If d = x then
(instructions)
or If e = x then
(instructions)
or If f = x then
(instructions)
Endif


Any help would be appreciated,

Ed


I'm having a little problem understanding your question.

In other words, what do you expect to happen if both b and e = x.

Assuming you just want to execute different instructions after the first
occurrence, you could use the If...Then...Else Statement

If a=x Then
[instructions]

[ElseIf b=x Then
[instructions]

[ElseIf b=x Then
[instructions]

....

End If

(Look up IF in VBA help)

However, if you want to execute instructions if any of a-f = x, then you could
use the OR operator:

IF _
a = x _
OR b = x _
OR c = x _
... _
Then
[instructions]
End If

Depending on the nature of the data, there may be other ways of executing this
test.




--ron