ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   or operator (https://www.excelbanter.com/excel-programming/381550-operator.html)

Ed

or operator
 
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

Ron Rosenfeld

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

merjet

or operator
 
An addenda to Rosenfeld's reply:
If a-f are mutually exclusive, you may want to use a Select Case
Statement, which you can find in Help.

Hth,
Merjet


Chip Pearson

or operator
 
I would use a Select Case statement. E.g.,

Select Case X
Case A
' do something
Case B
' something else
Case C
' something
' and so on
Case Else
' in case no match is found above
End Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"Ed" wrote in message
...
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




Ed

or operator
 
Thank you all. Decided to use case.

Thanks again,

Ed





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



All times are GMT +1. The time now is 09:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com