New here, and new to VBA and programming in general.
I am trying to reuse multiple arrays (through a loop), but I assume I need to clear them out before I reuse them? I have tried searching through the questions, but I can't find a solution, or frankly can't understand the solutions if they work.
Dim WS As Worksheet
For Each WS In Worksheets
If Right(WS.Name, 4) = "Data" Then Comp = Comp + 1
Next WS
Dim CompArray(10, 50) As Variant
Dim RatesArray(10, 1 To 50) As Variant
Dim IndexArray(10, 50) As Variant
Dim ShortIndexArray(10) As Long
Dim MRow, DRow, FRow, RRow, Col As Long
Dim LastCol, LastRow As Long
MRow = 4
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
Do Until MRow > LastRow
'**** MY CODE ****
''''***!!!*** Trying to Clear the array and reuse with the same dimensions for each loop ***!!!***
' not working
''Erase CompArray, RatesArray, IndexArray, ShortIndexArray
''ReDim CompArray(10, 50)
''ReDim RatesArray(10, 1 To 50)
''ReDim IndexArray(10, 50)
''ReDim ShortIndexArray(10)
MRow = MRow + 6 + Comp
Loop
End Sub
so when I go to the next step of the main loop, the arrays that I want to use have the same information. I want to keep the same names and dimensions of the arrays, but just clear out the contents. It sounds simple to me, but I have no idea how to do this.
I tried erasing and redim-ing (that was a solution to a similar problem on here) but it didnt work, it actually was saying I was declaring the arrays twice.
I also tried dim-ing the arrays while already in the loop. That didn't work either.
Any help would be appreciated!
Thanks.
ReDimworks. Try it again.ReDim CompArray(10, 50) As Variantwill fail.ReDim CompArray(10, 50)won't.ReDims were just uncommented, it should work.Array already dimensionederror, when you try toReDim.