Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclusive Or function (Office 2003)

    Hello

    Is it possible to create an Exclusive Or function in Excel? I'm working on a project that has a requirement to use this function along with a few other logic operators. If Excel will allow me to genrate an XOR then it makes life a little easier, if not I'll figure it out another way.

    Thanks.

    Ian

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Exclusive Or function (Office 2003)

    If you want to use a logical XOR function (as opposed to a bitwise XOR function), you can create this custom function in your Personal.xls:

    Public Function MyXOR(Arg1 As Variant, Arg2 As Variant) As Variant
    MyXOR = CBool(Arg1) Xor CBool(Arg2)
    End Function

    Use in a formula like this:

    =MyXOR(A1,A2)

    Note: you cannot name this function XOR since that is already a VBA function.

  3. #3
    Platinum Lounger
    Join Date
    Jan 2001
    Posts
    3,788
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Exclusive Or function (Office 2003)

    You can try the following:

    <code>=AND(OR(A1,B1),NOT(AND(A1,B1)))</code>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Exclusive Or function (Office 2003)

    Another (not quite equivalent) possibility is to combine OR and AND:

    =OR(A1,A2)-AND(A1,A2)

  5. #5
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Exclusive Or function (Office 2003)

    This also works if the cells are both boolean, though if you have numbers in them it can fail.
    =A1<>A2

    Steve

  6. #6
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Exclusive Or function (Office 2003)

    Great

    Thanks for the help, all methods seem to work fine.

    Ian

Posting Permissions

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