[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using constants



PureBytes Links

Trading Reference Links

Thanks for your email. I agree documentation is a pain. I've been able to
cut down on my documenting by using constants for the names of columns in my
VBA code. Once the constants are declared they're very easy to use.

In the procedure below, the two statements perform the same action (copy a
column and paste to a new location). The one with the constant is easier for
me to read and keep track of.

The "&" sign declares the constant as "long"

Best regards

Walter

===================

Option Explicit

Public Const colContractYear& = 1
Public Const colEntryDate& = 2
Public Const colEntryPrice& = 3
Public Const colExitDate& = 4
Public Const colExitPrice& = 5
etc.

Public Sub CopyColumns()
    Columns(colContractYear).Copy range("M1")
    Columns("A:A").Copy range("N1")
End Sub