I have an excel worksheet that I need to divide up into several smaller worksheets based upon the value of one column. The code works great, but runs out of resources when it gets past row 10k.
I think that the problem is when I'm trying to find the last row, so I was wondering if there was a more efficient workaround to avoid the memory problem. Or perhaps this isn't the problem anyway?
The code follows.
Sub Fill_Cells()
Dim masterSheet As Worksheet
Dim masterSheetName As String
Dim TRRoom As String, tabName As String
Dim lastRowNumber As Long
Dim j As Long
Application.ScreenUpdating = False
masterSheetName = "Master"
Set masterSheet = Worksheets(masterSheetName)
lastRowNumber = masterSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
j = 4
For Each c In masterSheet.Range("AB4:AB" & lastRowNumber).Cells
TRRoom = c.Value
tabName = "TR-" & TRRoom
localLastRowNumber = Worksheets(tabName).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
insertRow = localLastRowNumber + 1
Worksheets(tabName).Rows(insertRow).Value = masterSheet.Rows(j).Value
j = j + 1
Next
End Sub
If anyone could help me with this, I would appreciate it.