Dim statement to declare the object type of a variable

Results 1 to 4 of 4

Thread: Dim statement to declare the object type of a variable

  1. #1
    Board Regular
    Join Date
    Nov 2014
    Location
    Mumbai, Maharashtra, INDIA
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Dim statement to declare the object type of a variable

     
    I want to convert variable "COLUMNS" as an Integer from the current classification of "CONSTANT." When I change Const COLUMNS to Dim COLUMNS as Integer, I am getting an error in [Dim RN(1 To COLUMNS) As Range] statement. It says constant expression required. How can this be resolved? Basically I want to capture the number of columns via an input box and not keep it as constant.

    Code:
    Const COLUMNS = 31
    Dim s1 As Worksheet
    Dim s2 As Worksheet
    Dim Lags
    Dim RN(1 To COLUMNS) As Range

  2. #2
    Moderator mole999's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    8,552
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Dim statement to declare the object type of a variable

    I would have thought COLUMNS was a reserved word, maybe add an extra letter or number to it
    • Yes I know there are better ways to do it. I just wish I knew them. - 2003, 2007, 2010, 2013 & 2016
    • I wear my ignorance openly, excel is not my chosen career, its a means to an ends
    • Posting Guidelines Want to post well laid out questions and answers Translate Excel Versions
      Code:
      [CODE ]Put Your Code[/ CODE]
    • Settings > General Settings (on the left) scroll to the bottom, > Miscellaneous Options > Use ENHANCED
    • X-Posting Guidelines Rule 13 > CHART STUFF

  3. #3
    Board Regular Kyle123's Avatar
    Join Date
    Jan 2012
    Location
    Leeds, UK
    Posts
    2,271
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Dim statement to declare the object type of a variable

    Like this:
    Code:
    Dim COLUMNS As Integer
    Dim RN() As Range
    
    COLUMNS = 31
    ReDim RN(1 To COLUMNS)

  4. #4
    Board Regular
    Join Date
    Nov 2014
    Location
    Mumbai, Maharashtra, INDIA
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Dim statement to declare the object type of a variable

      
    @Kyle, thanks. It worked

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com