Using variables in variable names
Eliminate Pivot Table Annoyances
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Using variables in variable names

  1. #1
    New Member
    Join Date
    Feb 2002
    Posts
    13
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Can I use varaible as part of a variable name? For example, using looping actions, the procedure returns Weight (an integer variable) from row 2, then cycles through the remaining roews and returns additional Weight values. Each time thourgh the loop, I want to assign the returned value to a variable. The variable will be Weightk. The k represents the counting variable in the looping action. So the first returned value becomes Weight1, the second returned value becomes Weight2, etc.

    I have attempted Weight & k = Weight but get Compile error: expected expression as well as other forms.

    Any ideas?

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You could use an array, for example-

    WeightArray(k) = Weight

    Loop back through the array at the end to return your values.

    [ This Message was edited by: Mudface on 2002-02-28 08:29 ]

  3. #3
    MrExcel MVP Russell Hauf's Avatar
    Join Date
    Feb 2002
    Location
    Portland, OR Area - USA
    Posts
    1,605
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    You can use an array:

    Code:
    Dim aintWeight(2 to 20) as Integer
    Dim intRow as Integer
    
    For intRow = 2 to 20
        aintWeight(intRow) = Cells(intRow, 3)
    Next intRow
    
    ' Assumes weight values in column C
    
    ' ...
    Hope this helps,

    Russell

User Tag List

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