Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Syntax for "and" and "or"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
knowtrump - 22 Jan 2006 16:03 GMT
Can someone please show me the proper syntax for using "and" and "or"
operators with "if" in a Macro?  Can they be used together?

Signature

knowtrump

Bob Phillips - 22 Jan 2006 16:17 GMT
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)

> Can someone please show me the proper syntax for using "and" and "or"
> operators with "if" in a Macro?  Can they be used together?
[quoted text clipped - 4 lines]
> knowtrump's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=19664
> View this thread: http://www.excelforum.com/showthread.php?threadid=503802
Gary''s Student - 22 Jan 2006 16:25 GMT
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

> Can someone please show me the proper syntax for using "and" and "or"
> operators with "if" in a Macro?  Can they be used together?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.