kingofaces
Board Regular
- Joined
- Aug 23, 2010
- Messages
- 68
Basically, I'm trying to figure out the best way to create multiple arrays in VBA. Each array will be for a different location (n in the code below). Later on in a much larger macro I would like to be able to do calculations involving each location, so I want to reference to that specific array.
This is similar to what I'm trying to do. For each n (up to 10 here). I would like to create a new DDarray variable. Instead of repeating this code for DDarray1, DDarray2, . . . DDarray10, is there a way to keep the code concise like above? The n variable can change, so I will not know the number of arrays needed, and can't simply do anything like this:
Any ideas? I don't think there's a way to make part of a variable name another variable in itself is there?
Code:
Sub test()
a = WorksheetFunction.RandBetween(1, 20)
For n = 1 To 10
For x = 1 To 5
For y = 1 To 2
DDarray(x, y) = a
Next x
Next y
Next n
End Sub
This is similar to what I'm trying to do. For each n (up to 10 here). I would like to create a new DDarray variable. Instead of repeating this code for DDarray1, DDarray2, . . . DDarray10, is there a way to keep the code concise like above? The n variable can change, so I will not know the number of arrays needed, and can't simply do anything like this:
Code:
Sub test()
a = WorksheetFunction.RandBetween(1, 20)
For x = 1 To 5
For y = 1 To 2
DDarray1(x, y) = a
Next x
Next y
For x = 1 To 5
For y = 1 To 2
DDarray2(x, y) = a
Next x
Next y
'and so on
End Sub
Any ideas? I don't think there's a way to make part of a variable name another variable in itself is there?