Firstly, I will point out that the question around redimensioning a multi-dimensional array has been discussed and answered here: Excel VBA - How to Redim a 2D array?.
My issue is that I am trying to apply this answer and it isn't quite going smoothly! The issue is with calling the Function. If I dimension the array before calling the function, Excel just tells me it can't assign to the array (presumably because I'm not telling it which element to assign to). If I don't dimension the array beforehand then the function falls apart when it is looking for the dimensions of the old array...because it doesn't have any, presumably.
I know I can do the below by reversing the way round the array builds and then transposing it but I have need further on to change both dimensions of the array so am trying to get it working here first.
I will admit I'm at 'losing the will to live' stage with this code as I have been battling it for weeks and am an amateur wannabe programmer, so I realise it might be a really simple answer but I can't see it at the moment. Any help gratefully received.
Here's my code (the Sub is called from another sub, where all other variables are defined)
Sub CalculateRank(row, coln, TempSums, TempProducts, Lead_count)
Dim Maj As Double
Dim CompareCount As Integer
Dim CompareArray(1, 1) '**I don't really want to dimension this array before the loop below.
Maj = WorksheetFunction.Round(Range("FJudges") / 2, 0)
For coln = 1 To Lead_count
CompareCount = 0
For row = 1 To Lead_count
If TempSums(row, coln) >= Maj Then
CompareCount = CompareCount + 1
CompareArray = ReDimPreserve(CompareArray, CompareCount, 3) '**This is the line that is calling the function (copied directly from the bottom of the page linked above) and giving the error
CompareArray(CompareCount, 1) = row
CompareArray(CompareCount, 2) = TempSums(row, coln)
CompareArray(CompareCount, 3) = TempProducts(row, coln)
End If
Next row
Next coln
End Sub