Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Having "Or" in If statements in VB doesn't work?

I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Having "Or" in If statements in VB doesn't work?


You might want to tell us what a & b are.

--
Don Guillett
SalesAid Software

"J@Y" wrote in message
...
I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Having "Or" in If statements in VB doesn't work?

I would separate the line as follows:

If a = 2 then
blah blah blah
elseif b = 2 then
blah blah blah
End If

Or, if you want to test for both equalling 2:
If a = 2 then
If b = 2 then
etc.
--
Pops Jackson


"J@Y" wrote:

I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Having "Or" in If statements in VB doesn't work?

On Jun 15, 11:27 am, J@Y wrote:
I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?


If a = 2, the Or expression will evaluate to True regardless of the
value of b. If you require both variables to be equal to 2 to get a
result of True you need to use And rather than Or:

If a = 2 and b = 2 then [...]

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Having "Or" in If statements in VB doesn't work?

It isn't, at least for me:

Dim a As Long
Dim b As Long

a = 0
b = 0
If a = 2 Or b = 2 Then MsgBox "a: " & a & " b: " & b
a = 2
b = 0
If a = 2 Or b = 2 Then MsgBox "a: " & a & " b: " & b
a = 0
b = 2
If a = 2 Or b = 2 Then MsgBox "a: " & a & " b: " & b



In article ,
J@Y wrote:

I was trying this statement:

If a = 2 or b =2 then .....

But the b = 2 doesn't get tested for some reason, why is that?

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
=SUBSTITUTE(C4,"~?#","") will this work to remove multiple string Raja Mahendiran S Excel Worksheet Functions 6 May 12th 10 09:10 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Read ".dll" files, the Macro "work flow" and the actual values of the variables when Macro is running [email protected] Excel Programming 5 May 16th 07 08:18 PM
pictures to work with "data" "sort" option arad Excel Discussion (Misc queries) 1 April 18th 06 09:15 PM
I'm desperate I posted earlier about "If" statements that don't work but are correct. Now... Marc Excel Worksheet Functions 2 April 5th 06 09:27 PM


All times are GMT +1. The time now is 04:12 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"