What Is a DIM Statement in Excel?

by Robert Karr

DIM is a computer “word” in Visual Basic for Applications (VBA), a special subset of Visual Basic built into Microsoft Excel and other Microsoft Office programs to develop macros.

History

DIM was part of the early versions of BASIC (Beginner’s All Purpose Symbolic Instruction Code) computer language developed by two mathematicians, John George Kemeny and Tom Kurtzasat Dartmouth College, in 1964.

Types

The DIM statement declares many different types of variables in BASIC or VBA. These include whole numbers (byte, integer or long), floating-point numbers (single or double), string (alphanumeric), currency, date, Boolean and object.

Word Origin

DIM originally stood for “Dimension” referring to the size of arrays (matrices of variables) or the type of variable used. More commonly, programmers refer to DIM as “declaring” the type of variable.

Importance

In versions of Visual Basic, including VBA in Excel, if the type of variable is not declared, it defaults to a “variant” type. When the code executes, if the program has to determine how to best use the variable, it may slow down the application.

Expert Insight

Placing the words “Option Explicit” (without the quotation marks) at the very beginning of a code module in VBA in Excel will trap any attempt at use of an undeclared variable. This will prevent later problems.

About the Author

Robert Karr has been a writer, indexer, reference librarian, computer programmer and Web designer. He has a Master’s Degree in Library Science. Karr has 30 years experience in reference and research and has been writing professionally for 25 years, focusing on the library, medical and computer areas.

Photo Credits

  • photo_camera BananaStock/BananaStock/Getty Images