Writing Declaration Statements

You use declaration statements to name and define procedures, variables, arrays, and constants. When you declare a procedure, variable, or constant, you also define its scope, depending on where you place the declaration and what keywords you use to declare it.

The following example contains three declarations.

  Sub ApplyFormat()
    Const limit As Integer = 33
    Dim myCell As Range
    ' More statements
End Sub

The Sub statement (with matching End Sub statement) declares a procedure named

  ApplyFormat

. All the statements enclosed by the Sub and End Sub statements are executed whenever the

  ApplyFormat

procedure is called or run.

The Const statement declares the constant

  limit,

specifying the Integer data type and a value of 33.

The Dim statement declares the variable

  myCell

. The data type is an object, in this case, a Microsoft Excel Range object. You can declare a variable to be any object that is exposed in the application you are using. Dim statements are one type of statement used to declare variables. Other keywords used in declarations are ReDim, Static, Public, Private, and Const.