Common VBA commands in MS excel

Written by jae chapman
  • Share
  • Tweet
  • Share
  • Pin
  • Email
Common VBA commands in MS excel
(Comstock Images/Comstock/Getty Images)

VBA commands get MS Excel to do what you want -- and quicker than flipping through all the menus on the navigation bar. Programmers use VBA to write macros in MS Excel; these macros can perform functions that might be specific to your application. Programmers can benefit from keeping a VBA language reference handy to look up how to implement new functionality. A few VBA commands are quite common and useful to learn right away.

Other People Are Reading

Message Box

A message box, or more commonly referred to as "that annoying pop-up," allows Excel to interact with users. The VBA command, "MsgBox" (without quotes) is used to create message boxes. The programmer uses VBA to define what information would be given to the user in a message box, what information will be input by the user and what will be done with that information.

Selecting Cells

The VBA command, Range, refers to a cell or a group of cells. Combined with the object property, Value -- as in "Range("A1").Value" (without opening and closing quotes) -- you can select the contents of a cell.


Programmers often need to loop through multiple instances of an object to fully implement a function. For MS Excel, the VBA commands for looping are "For Each...Next" (without quotes).


Lets face it, programmers are human and will forget the intended purpose of a VBA command. One way to avoid forgetting is to comment extensively throughout the VBA code. The most common way to comment in VBA for Excel is to use the apostrophe, but there is a longer command, "Rem" (without quotes) that can be used for those who prefer not to use punctuation in code.

Speeding Up Calculations

MS Excel defaults to automatically calculate formulas, or you can calculate formulas -- updating them based on changes in information -- by pressing the "F9" key. However, both of these methods require stepping in and back out of VBA if your formulas call for user-defined VBA functions, slowing down calculation. According to Microsoft, you can prevent MS Excel from calculating outside of VBA by redirecting the "F9" key with a private subroutine of the following:

Application.OnKey "{F9}", "Recalc"

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.