Home

Consulting

Excel VBA

Legal

Links

Contact

About Us

If

There are two types of "If" statements in Excel:
  • Excel "=if"
  • VBA "If - Then - Else
The "if" statement is one of the most important programming statements. It's what makes computers smart. The "if" statement tests for a condition and if the condition is true performs a series of steps. If the condition is false it performs a different series of steps. People use "if" statements all the time.

For example when you enter your house on a dark night your brain does the following "if" statement:

if (the lights are on) then
     walk into the house
else if (the lights are off) then
     turn on the lights
     walk into the house
end if

Excel "=if"

The syntax for the "if"

=if ( <condition>, <true value>, <false value>)

If the condition is truem the cell gets the result of the . If the condition is false the cell gets the value of the

Examples:

Cell Contents Result
A1 7  
A2 =if(a1=7,"seven","not seven") seven

VBA "If - Then - Else