Hi,
Got a dynamic array (arr1) that changes in size (currently 2182 rows x 17 columns)
Looping through the arr1 I’m searching for a user provided variable in a specific column (say column 2). The value is a given criteria (eg. “company name”) If the loop encounters a company that meets the criteria, it adds the value in each column to another array (arr2).
In this way, once I’m through arr1, I have in arr2 a subset of arr1 representing only the values I need to work with.
My problem is to fill arr2. Redim preserve will not do it for me as it only allows adjustment of the last dimension of the array.
Other people must have had similar problems . How would you normally go about this??
Below is my current code:
Dim varGetArrayTransactions as Variant
Public Sub Test_TransStep()
Dim arrTransList()
Dim sRangeAdr As String
Dim sCoName As String
Dim c, d, e
e = 1
‘For test purposes – set Company name
sCoName = “MyCompany”
‘Returns range as string and has entire array loaded in varGetArrayTransactions
sRangeAdr = Get_RangeAddresses(sSheetName:=SHT_TRANSACTIONS, sRowToGet:=”Range”, arrRangeLoad:=varGetArrayTransactions)
‘Loop entire array
For c = 1 To UBound(varGetArrayTransactions, 1)
‘Can we find a matching company?
If sCoName = varGetArrayTransactions(c, 2) Then
‘Match found – add values from each column to new array (arrTransList)
For d = 1 To UBound(varGetArrayTransactions, 2)
‘This bit doesn’t work…!!¤#¤!”#!#!”
ReDim Preserve arrTransList(e, UBound(varGetArrayTransactions, 2))
arrTransList(e, d) = varGetArrayTransactions(c, d)
Debug.Print “Item (” & e & “,” & d & “): ” & arrTransList(e, d)
Next d
e = e + 1
End If
Next c
TIA