Kdbailey
Board Regular
- Joined
- Aug 1, 2012
- Messages
- 156
I am having a hard time gettin my multi-dimension array to work. The basic idea of what I am doing is collecting 4 pieces of information to go with the first dimension. What it is doing is looping through, and adding new items to the array, and I do not know what the final count of items will be so I need the redim preserve the array. This code gives me the correct information for (0,0), (0,1), (0,2), (0,3) but then as soon as it tries for (1,0) the subscript is out of range. I do not fully understand how to redimension a multi-dimension array.
a is jumping down to specific rows, b is jumping over to specific columns
a is jumping down to specific rows, b is jumping over to specific columns
Code:
Private Sub CommandButton3_Click()Dim start_row6 As Integer, start_row3 As Integer, start_colcost As Integer, start_colinc As Integer
Dim sheet As Variant
Dim ws As Worksheet
Dim list1() As Variant
Dim a As Integer, b As Integer, r As Integer, index As Integer, index2 As Integer
sheet = Array("Hawk", "I2", "I3", "GE V4", "GE V6", "TBIRD", "BAT")
index = 0
For r = 0 To 6
Set ws = ActiveWorkbook.Sheets(sheet(r))
For a = 0 To 14
start_row3 = 3 + (a * 44)
For b = 0 To 1
index2 = 3
start_colcost = 9 + (b * 12)
ReDim Preserve list1(index, index2)
index2 = 0
list1(index, index2) = ws.Cells(start_row3 + 1, start_colcost - 7)
index2 = index2 + 1
list1(index, index2) = ws.Cells(start_row3 + 1, start_colcost - 6)
index2 = index2 + 1
list1(index, index2) = ws.Cells(start_row3 + 1, start_colcost - 3)
index2 = index2 + 1
list1(index, index2) = ws.Cells(start_row3, start_colcost)
index = index + 1
Next b
For b = 2 To 4
start_colcost = 26 + (b * 12)
index = index + 1
ReDim Preserve list1(3, index)
list1(0, index) = ws.Cells(start_row3 + 1, start_colcost - 7)
list1(1, index) = ws.Cells(start_row3 + 1, start_colcost - 6)
list1(2, index) = ws.Cells(start_row3 + 1, start_colcost - 3)
list1(3, index) = ws.Cells(start_row3, start_colcost)
Next b
Next a
Next r
End Sub