#1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 46
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 46
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
about & operator [email protected] Excel Discussion (Misc queries) 2 December 12th 08 04:44 PM
Operator kittycris Excel Worksheet Functions 3 January 11th 07 01:36 AM
what does ~ operator mean? Todd Excel Discussion (Misc queries) 3 November 22nd 05 05:30 PM
Mod operator R Avery Excel Programming 7 September 2nd 04 03:03 AM
Like Operator Donald[_3_] Excel Programming 8 June 29th 04 03:22 AM


All times are GMT +1. The time now is 07:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"