我有一个 Excel 工作表,我需要根据一列的值将其分成几个较小的工作表。该代码运行良好,但是当它超过第 10k 行时会耗尽资源。
我认为问题出在我试图找到最后一行时,所以我想知道是否有更有效的解决方法来避免内存问题。或者也许这不是问题所在?
代码如下。
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
如果有人可以帮助我,我将不胜感激。