Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA code for IF statement with OR?

I would like to know how to do an If statement in VBA which is the similar
to using OR in excel functions. eg.


I would like to do something like

If Var1 = 23 or 34 then
Var = "Hello"
end if


any help is appreciated, thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default VBA code for IF statement with OR?

One way:

If Var1 = 23 Or Var1 = 34 Then Var = "Hello"

In article ,
"Dave R." wrote:

I would like to know how to do an If statement in VBA which is the similar
to using OR in excel functions. eg.


I would like to do something like

If Var1 = 23 or 34 then
Var = "Hello"
end if


any help is appreciated, thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA code for IF statement with OR?

Perfect! Thanks!


"JE McGimpsey" wrote in message
...
One way:

If Var1 = 23 Or Var1 = 34 Then Var = "Hello"

In article ,
"Dave R." wrote:

I would like to know how to do an If statement in VBA which is the

similar
to using OR in excel functions. eg.


I would like to do something like

If Var1 = 23 or 34 then
Var = "Hello"
end if


any help is appreciated, thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA code for IF statement with OR?


Good evening Dave R

This is how to do what you are asking. The code will throw up a
message box containing the value of Var, only if Var1=23 or 34, so
change the value of Var1 and re-run the code to see the routine in
action.

Sub Demo()
Var1 = 23 'Change this value and re-run the code
If Var1 = 23 Or Var1 = 34 Then
Var = "Hello"
MsgBox Var
End If
End Sub

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=382126

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA code for IF statement with OR?

Thank you DominicB.


"dominicb" wrote in
message ...

Good evening Dave R

This is how to do what you are asking. The code will throw up a
message box containing the value of Var, only if Var1=23 or 34, so
change the value of Var1 and re-run the code to see the routine in
action.

Sub Demo()
Var1 = 23 'Change this value and re-run the code
If Var1 = 23 Or Var1 = 34 Then
Var = "Hello"
MsgBox Var
End If
End Sub

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile:

http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=382126



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
Help Identifying code statement Ayo Excel Discussion (Misc queries) 1 November 29th 07 03:50 AM
If statement to replace #VALUE! code jeannie v Excel Worksheet Functions 8 June 27th 07 03:53 AM
Worksheet code if-color-statement Jonsson[_43_] Excel Programming 1 September 29th 04 03:57 PM
Code doesn't go past first IF statement keepITcool Excel Programming 2 July 20th 04 09:48 PM
Simple code error statement Stuart[_5_] Excel Programming 7 March 3rd 04 08:47 PM


All times are GMT +1. The time now is 08:15 PM.

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

About Us

"It's about Microsoft Excel"