What if you replace your range variables Balance and MRDate, to arrays or collections?
I'm not sure that you can redim ranges. You can resize, but in case put data in memory... doesn't work.
Out of Memory Error when initiallizing array
Erick Christensen
6
Reputation points
I am trying to assign an array to a range, and it runs fine until it gets to assigning:
TD.Range("K2", "K" & Size + 1).Value = Balance
TD.Range("L2", "L" & Size + 1).Value = MRDate
Upon this point it throws an Out of Memory error. Any thoughts?
Dim Headers As Variant
Headers = Array("Client", "Balance", "Mail Received Date")
Range("J1:L1").Value = Header
Dim Balance() As Range
Dim MRDate() As Range
Dim Size As Long
Dim i As Long
i = 1
Size = WorksheetFunction.CountA(Client_Names)
ReDim Balance(Size)
ReDim MRDate(Size)
For i = 1 To Size
Set Balance(i) = TD.Range("H" & TD.Range("A:A").Find("Total " & Client_Names(i)).Row)
Set MRDate(i) = TD.Range("E" & TD.Range("D1", "D" & Balance(i).Row).Find("Mail Received*", SearchDirection:=xlPrevious).Row)
Next i
TD.Range("J1:L1").Value = Headers
TD.Range("J2", "J" & Size + 1).Value = WorksheetFunction.Transpose(Client_Names)
TD.Range("K2", "K" & Size + 1).Value = Balance
TD.Range("L2", "L" & Size + 1).Value = MRDate
Developer technologies | Visual Basic for Applications
Developer technologies | Visual Basic for Applications
An implementation of Visual Basic that is built into Microsoft products.
2 answers
Sort by: Most helpful
-
Oskar Shon 49,311 Reputation points Volunteer Moderator2022-11-17T14:42:21.697+00:00 -
Viorel 125.6K Reputation points2022-11-17T15:47:01.31+00:00 Try several modifications:
ReDim Balance(Size - 1) ReDim MRDate(Size - 1) . . . For i = 0 To Size - 1 . . . TD.Range("K2", "K" & Size + 1).Value = WorksheetFunction.Transpose(Balance) TD.Range("L2", "L" & Size + 1).Value = WorksheetFunction.Transpose(MRDate)