By using vba.booksticle.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

948 Steps to 6 Figures by Learning Excel-VBA and Other Skills



Step - Dim


Dim is short for Dimension statement.

If you're declaring variables, then one way is with the Dim statement:

Examples:
  • Dim i
  • Dim i as Integer
  • Dim s as String
  • Dim v as Variant
  • Dim x as Integer, y as Integer

    You can declare Arrays by:
  • Dim a(7) as Integer ' a is an array with 8 elements from 0 to 7

    Option Explicit

    If a module has this set then all variables must be declared before usage. There are advantages and disadvantages to this:
  • Pros - Reduces errors because it catches misspellings
  • Cons - It takes more time to declare variables

    Variable Scope

    When you declare a variable it's scope can be:
  • Public - All routines can see the value
  • Module - Only code in the Module can see the value
  • Local - The variable is only available to the local Subroutine or function

  •    Table of Contents | Send us your feedback | © 2025 All Rights Reserved | Edit