I am trying to learn to build a 2d array, by finding the data and then populating the value of it.
In the below example, I have a used range that starts in Cells(7,7) and continues to Cells(11,8). Very small data set I am using for learning.
When I get all the way to the bottom and use the MsgBox arrtest(7,8), how can I change this to use relative instead. I would like to use arrtest(1,2), or arrtest(1,1), even though this data starts in column 7 row 7.
Thanks.
In the below example, I have a used range that starts in Cells(7,7) and continues to Cells(11,8). Very small data set I am using for learning.
When I get all the way to the bottom and use the MsgBox arrtest(7,8), how can I change this to use relative instead. I would like to use arrtest(1,2), or arrtest(1,1), even though this data starts in column 7 row 7.
Thanks.
Code:
Sub arrSet()
Dim arrtest() As Variant
Dim firstRow, firstCol, lastRow, lastCol As Integer
Call reset_usedrange
lastRow = ActiveSheet.UsedRange.Rows.Count
lastCol = ActiveSheet.UsedRange.Columns.Count
firstRow = Cells(ActiveCell.Row, ActiveCell.Column).End(xlUp).Row
firstCol = Cells(firstRow, ActiveCell.Column).End(xlToLeft).Column
If ActiveCell.Column - firstCol > 1 Then
firstCol = ActiveCell.Column
End If
ReDim arrtest(firstRow To lastRow + firstRow - 1, firstCol To lastCol + firstCol - 1)
For i = firstRow To lastRow + firstRow - 1
For j = firstCol To lastCol + firstCol - 1
arrtest(i, j) = Cells(i, j).Value
Next j
Next i
[U][B]MsgBox arrtest(7, 8)[/B][/U]
End Sub
Public Sub reset_usedrange()
a = ActiveSheet.UsedRange.Rows.Count
End Sub