For work, I'm working with arrays in which I store prices of parts. The idea is that I have an array with the different part numbers coded on several digits, I go in the excel workbook where all the parts and their prices are stored and search for these codes one by one. Once a code found, I just do an "offset" to get the price in Euro and in Dollards, and fill another array with these prices.
My problem is that when the array with the parts numbers got only one part number, I don't achieve to "ReDim" the array to be a 1x2 array...
See the comments in the following code (Yes, I chose to start the arrays at 1 and not 0, it's way more convenient in this case)
Dim ToolPrices() As String
ReDim ToolPrices(1 To UBound(ToolTab()), 1 To UBound(ToolTab())) 'Normally, if "ToolTab()" is a 1x1 array, TooLPrices should be a 1x2 array... But no, it's a 1x1
[Later on in the code]
Tempo = ActiveCell.Offset(0, 2) 'gets the euro price
' the variable PositionPoint is the pointer for the "for" loop passing through all the arrays
If PositionPoint > UBound(ToolPrices(), 1) Then 'for avoiding to reduce the size of the Array and loosing data
ReDim Preserve ToolPrices(1 To 2, 1 To PositionPoint)
End If
ToolPrices(1, PositionPoint) = Tempo
Tempo = ActiveCell.Offset(0, 5) 'gets the dollard price
If PositionPoint > UBound(ToolPrices(), 2) Then 'for avoiding to reduce the size of the Array and loosing data
ReDim Preserve ToolPrices(1 To 2, 1 To PositionPoint)
End If
ToolPrices(2, PositionPoint) = Tempo 'In case of a 1x1 array with the parts numbers, this bugs as it is a 1x1 array in which I try to put something in the second line
I've been searching for a while without success...
I guess either the ReDim ToolPrices(1 To UBound(ToolTab()), 1 To UBound(ToolTab()))
got a problem...
OR
the If PositionPoint > UBound(ToolPrices(), 2) Then
ReDim Preserve ToolPrices(1 To 2, 1 To PositionPoint)
End If
which isn't accessed as the UBound(ToolPrices(), 2) = 1
when I would expect a 0 or "Empty" or "" or error or anything except a 1 as the second dimension don't exist...
Thank's by advance for your help !