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.
- photo_camera BananaStock/BananaStock/Getty Images