Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Oct 2005
    Location
    Calgary, Alberta
    Posts
    205
    Thanks
    0
    Thanked 1 Time in 1 Post

    using the const option (excel 2003)

    I am trying to figure out the option of making a varible a constant and definging it as a range in the work book. Could someone explain to me how this function works and how do i use a named range as a constant??


    Const vNumber As String = Sheets("Page 1").Range("Number").Value

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: using the const option (excel 2003)

    You can't. A constant is, well, a constant. The value of a cell can change. So vNumber must be a variabe.

  3. #3
    2 Star Lounger
    Join Date
    Oct 2005
    Location
    Calgary, Alberta
    Posts
    205
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: using the const option (excel 2003)

    Hi there Hans,
    ok well is there to have all my varibles at the top of the module and each different sub uses the varibles at the top? I would like to have it this way so its easy to main tain large code,?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: using the const option (excel 2003)

    Yes, you can declare a variable at the top of the module, below the line Option Explicit (if you have one, and you should), but before all functions and subs. If you declare it as Private, for example

    Private strThis As String

    you can use it in all functions and subs in that module, but not in other modules. If you declare it as Public, for example

    Public lngThat As Long

    you can use it in all functions and subs in all modules in the workbook. In both cases, you must set the value of the variable in a function or sub. Thereafter, the value will be known to the other functions or subs.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •