"And" and "Or" troubles within an IF statement

excel, vba

Solution

The problem is probably somewhere else. Try this code for example:

Sub test()

  origNum = "006260006"
  creditOrDebit = "D"

  If (origNum = "006260006" Or origNum = "30062600006") And creditOrDebit = "D" Then
    MsgBox "OK"
  End If

End Sub

And you will see that your `Or` works as expected. Are you sure that your `ElseIf` statement is executed (it will not be executed if any of the if/elseif before is true)?

Problem

I'm trying to use "And" & "Or" within an If statement. I probably have my syntax wrong. the result comes back false when the data should make it true. Here is the code: ``` ElseIf (origNum = "006260006" Or origNum = "30062600006") And creditOrDebit = "D" Then 'do things here End If ``` -When I debug and come to this line it hops over it and doesn't enter in. -origNum actually equals "006260006" and creditOrDebit = "D". -so I'm assuming my "Or" statement isn't working. -Hopefully this is a quick easy question. Thanks!

Original source