+ Reply to Thread
Results 1 to 3 of 3

Syntax for "and" and "or"

  1. #1
    Registered User
    Join Date
    02-09-2005
    Posts
    51

    Question 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?

  2. #2
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote
    in message news:[email protected]...
    >
    > 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. #3
    Gary''s Student
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1