• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 33. Taking More Control of Your ... > Understanding VBA Control Structures

Understanding VBA Control Structures

Many VBA macros run in a simple fashion. Starting with the Sub statement, they execute every statement in the macro, from start to finish. This is fine as long as you want the macro to do the same thing every time, but sometimes you need a macro that's a little smarter than that. VBA provides a wide variety of program control structures that enable you to change the way the statements are executed, depending upon conditions that are found while the macro is running.

Using the If…Then…End If Statement

Perhaps the simplest and most commonly used control structure in VBA is the If…Then…End If statement. This statement enables you to execute a group of VBA statements only if some condition is true. Consider an example of why this might be necessary.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint