Using variables in variable names

tanda

New Member
Joined
Feb 18, 2002
Messages
13
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?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top