Simply put the if statement determines if a condition is true or false and then performs some action based on the results of that determination. In the three if statement examples below, I add a level of complexity and utility.  Pay attention to how they flow

 

If activecell.value > .2 then
activecell.interior.color = 255
end if

The first line of this simple if statement checks to see if the active cells value (the currently selected cell) is greater than .2.
If true, it reads the next line and sets the color to 255 Red.
If false, it jumps to the end if and creates no action.

If activecell.value > .2 then
activecell.interior.color = 255
else
activecell.interior.color = 65535
end if

By adding the else, we are essentially saying if its true color it red and if it is not, color it yellow

If activecell.value > .2 then
activecell.interior.color = 255
elseif 
activecell.value > .18 then
activecell.interior.color = 65535
else
activecell.interior.color = 5287936
end i

If the active cell value is greater than .2, make it red.
else if it is greater than .18, make it yellow.
otherwise make it green.

If you have any suggestions, comments or would like to discuss help you need automating your next project, you can contact me here 

Close Menu

Excel and VBA Craftsman offers experienced VBA Development: Complete GUI Driven Applications, Automated Reconciliations, VBA ODBC Database Data Mining, VBA Excel, Access, Outlook and Word Customization. VBA Custom Functions, VBA Concept Assessment, VBA integration of MS office applications into powerful single seamless solutions, Excel Help, Automate Excel, Excel Automation