Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Syntax for "and" and "or"


Can someone please show me the proper syntax for using "and" and "or"
operators with "if" in a Macro? Can they be used together?


--
knowtrump
------------------------------------------------------------------------
knowtrump's Profile: http://www.excelforum.com/member.php...o&userid=19664
View this thread: http://www.excelforum.com/showthread...hreadid=503802

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Syntax for "and" and "or"

The best way is to use brackets to isolate the conditions.

If (A And B) Or _
(C And D) And _
(E Or D) Then
'do you stuff
End If

Note though that VB does not short circuit when testing, which can cause
problems, which are invariably worse, more likey, harder to debug with such
conditions. This means that even if a condition is met that would cause the
overall test to fail, it still runs the other tests. If they could give rise
to errors, you will get the error even if that test is irrelevenat in a
particular case.

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"knowtrump" wrote
in message ...

Can someone please show me the proper syntax for using "and" and "or"
operators with "if" in a Macro? Can they be used together?


--
knowtrump
------------------------------------------------------------------------
knowtrump's Profile:

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Syntax for "and" and "or"

Sub M()
Dim i, j, k As Integer
i = 1
j = 2
k = 3
If (i = 1 And j = 2) Or k = 3 Then
MsgBox ("true")
End If
End Sub
____________________________
Gary's Student


"knowtrump" wrote:


Can someone please show me the proper syntax for using "and" and "or"
operators with "if" in a Macro? Can they be used together?


--
knowtrump
------------------------------------------------------------------------
knowtrump's Profile: http://www.excelforum.com/member.php...o&userid=19664
View this thread: http://www.excelforum.com/showthread...hreadid=503802


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
correct syntax for nesting "if", "and", and "vlookup"....if possib Christine Excel Worksheet Functions 4 January 2nd 09 10:43 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
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 08:51 AM.

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"