С каждым рабочим листом увеличивается объем памяти, я обнаружил, что если я скопирую строки и столбцы, в которых были данные, и поместил их на новый лист, затем удалил старый и переименовал новый с тем же именем, я мог бы уменьшить свой размер книги от 1 до 3 мегабайт, это не проблема памяти, но мой код, кажется, работает быстрее, когда книга меньше. Я загрузил программу, которая может удалить все неиспользуемые ячейки, но не может заставить ее работать.
Sub Reset_LastCell()
' http://support.microsoft.com/default...&Product=xlw2K
' Save the lastcell and start there.
Dim Sh As Worksheet
Dim A As Integer
For Each Sh In Worksheets
A = A + 1
If A >= 28 Then
Sh.Activate
Set lastcell = Cells.SpecialCells(xlLastCell)
' Set the rowstep and column steps so that it can move toward
' cell A1.
rowstep = -1
colstep = -1
' Loop while it can still move.
While (rowstep + colstep <> 0) And (lastcell.Address <> "$A$1")
' Test to see if the current column has any data in any
' cells.
If Application _
.CountA(Range(Cells(1, lastcell.Column), lastcell)) _
> 0 Then colstep = 0 'If data then stop the stepping
' Test to see if the current row has any data in any cells.
' If data exists, stop row stepping.
If Application _
.CountA(Range(Cells(lastcell.Row, 1), lastcell)) _
> 0 Then rowstep = 0
' Move the lastcell pointer to a new location.
Set lastcell = lastcell.Offset(rowstep, colstep)
' Update the status bar with the new "actual" last cell
' location.
Application.StatusBar = "Lastcell: " & lastcell.Address
Wend
' Clear and delete the "unused" columns.
With Range(Cells(1, lastcell.Column + 1), "IV65536")
Application.StatusBar = "Deleting column range: " & _
.Address
.Clear
.Delete
End With
' Clear and delete the "unused" rows.
With Rows(lastcell.Row + 1 & ":65536")
Application.StatusBar = "Deleting Row Range: " & _
.Address
.Clear
.Delete
End With
' Select cell A1.
' Reset the status bar to the Microsoft Excel default.
Application.StatusBar = False
If A >= 35 Then Exit Sub
Range("AI2").Select
End If
Next
End Sub