Excel 删除空单元格(非常慢)
我有一个要删除所有空单元格的范围。我开发了以下解决方案,但速度非常慢。有谁能帮助我理解为什么这是如此的简单,以及什么样的方法会导致更快的解决方案Excel 删除空单元格(非常慢),excel,vba,Excel,Vba,我有一个要删除所有空单元格的范围。我开发了以下解决方案,但速度非常慢。有谁能帮助我理解为什么这是如此的简单,以及什么样的方法会导致更快的解决方案 Application.ScreenUpdating = False For i = letzte2 To 4 Step -1 For j = 2 To 17 If tab6.Cells(i, j) = "" Then tab6.Cells(i, j).Delete shift:=
Application.ScreenUpdating = False
For i = letzte2 To 4 Step -1
For j = 2 To 17
If tab6.Cells(i, j) = "" Then
tab6.Cells(i, j).Delete shift:=xlUp
End If
Next j
Next i
Application.ScreenUpdating = True
只执行一次删除操作:
Dim rDel As Range
Set rDel = Nothing
Application.ScreenUpdating = False
For i = Letzte2 To 4 Step -1
For j = 2 To 17
If tab6.Cells(i, j) = "" Then
If rDel Is Nothing Then
Set rDel = tab6.Cells(i, j)
Else
Set rDel = Union(rDel, tab6.Cells(i, j))
End If
End If
Next j
Next i
If Not rDel Is Nothing Then
rDel.Delete shift:=xlUp
End If
Application.ScreenUpdating = True
这可以通过使用
SpecialCells()
方法非常简单(并且有效)地完成。以下操作将删除选定内容中的所有空单元格
Sub DeleteEmptyCells()
Dim Rng As Range
Set Rng = Selection.SpecialCells(xlCellTypeBlanks)
If Not Rng Is Nothing Then
Rng.Delete shift:=xlUp
End If
End Sub
多好的解决方案啊。非常感谢你!