11.3. If Statements

As in most programming languages, If statements are among the most immediately useful and versatile commands for making decisions in VBA.

In this section, you'll look at the following types of If statements:

  • If... Then

  • If... Then... Else

  • If... Then... ElseIf... Else

11.3.1. If... Then

If... Then statements tell VBA to make the simplest of decisions: if the condition is met, execute the following statement (or statements); if the condition isn't met, skip to the line immediately following the conditional block. An If block statement begins with If and concludes with End If. However, a short If... Then statement can be written entirely on a single line, in which case the End If is omitted.

11.3.1.1. Syntax

If... Then statements ...

Get Mastering VBA for Microsoft Office 2007, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.