【发布时间】:2012-03-30 07:55:18
【问题描述】:
我有以下代码从 A 列中获取空行,然后删除整行。我无法在 2010 年使用 Special--> Blanks --> Delete Sheet Rows 功能,因为 2007 年的上限约为 8000 个非连续行。这段代码在一些旧机器上非常慢,大约需要 40 分钟才能完成(但可以完成工作)。有没有更快的替代方案?
Private Sub Del_rows()
Dim r1 As Range, xlCalc As Long
Dim i As Long, j As Long, arrShts As Variant
With Application
xlCalc = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
arrShts = VBA.Array("Sheet1") 'add additional sheets as required
For i = 0 To UBound(arrShts)
With Sheets(arrShts(i))
For j = .UsedRange.Rows.Count To 2 Step -8000
If j - 7999 < 2 Then
.Range("A2:A" & j).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Else
.Range("A" & j, "A" & j - 7999).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End If
Next j
End With
Next i
Application.Calculation = xlCalc
【问题讨论】:
标签: excel vba excel-2007