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.
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.
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.
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.
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.
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.
- Wellesley College: History of Basic
- University of Maryland: Introduction to QuickBASIC
- LearnThat: DIM Statement Definition
- Mastering VBA; Guy Hart-Davis; 2005
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.