• Exclusive Or function (Office 2003)

    Author
    Topic
    #415641

    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

    Viewing 3 reply threads
    Author
    Replies
    • #927477

      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.

    • #927478

      You can try the following:

      =AND(OR(A1,B1),NOT(AND(A1,B1)))

    • #927479

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

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

    • #927482

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

      Steve

    Viewing 3 reply threads
    Reply To: Exclusive Or function (Office 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: