Using AND in the THEN branch of an IF statement


Does VBA allow use of the AND statement in the THEN branch of the IF statement?

If cel.Offset(0, 6).Value = "HardToken" Then wshT.Cells(r, 14).Value = "Physical" And wshT.Cells(r, 19).Value = cel.Offset(0, -2).Value

If not - then how do you restructure the above?

AND is a boolean operator used to establish if a condition is met. It is only used in the condition part of an IF() statement, and NEVER in the "Then" branch to add more commands to a statement.

In pseudo code:

If CellA1 equals "blue" AND CellB1 equals "green" then
   msgbox("A1 is blue")
   msgbox("B1 is green")
end if

You cannot use AND to add another statement to your code. You don't need to. In the above code sample the two message boxes will appear one after the other. But only if the two conditions are met. The two conditions are joined with an AND operator, so the message boxes will only appear if BOTH conditions are true.

From your sample code it seems that you simply want to thread a number of actions if a single condition is true. You don't need the AND in there at all.

If something = somethingElse then
   do this
   do that
   do the other
end if

No AND required.