使用VBA隐藏空行-提高速度
我试图隐藏单元格文本长度等于零的行。 目前正在使用以下代码,但由于逐行分块,速度非常慢:使用VBA隐藏空行-提高速度,vba,hide,rows,Vba,Hide,Rows,我试图隐藏单元格文本长度等于零的行。 目前正在使用以下代码,但由于逐行分块,速度非常慢: Sub HideRows() Application.ScreenUpdating = False Application.EnableEvents = False ActiveSheet.DisplayPageBreaks = False Application.DisplayAlerts = False Dim cell As Range For Each cell In Range("B1:B100
Sub HideRows()
Application.ScreenUpdating = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Application.DisplayAlerts = False
Dim cell As Range
For Each cell In Range("B1:B1000")
If Not IsEmpty(cell) Then
If Len(cell.Text) = 0 Then
cell.EntireRow.Hidden = True
End If
End If
Next
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub
我在其他地方见过你可以用的
Rng.SpecialCells(xlCellTypeBlanks).EntireRow.Hidden = True
但因为我的单元格不是空的,只是给你一个公式中的“”的结果,所以我觉得这个对我不起作用
有没有其他方法可以提高这个过程的效率 您可以在一个操作中隐藏所有行,如下所示:
Sub hideRows()
Dim rng As Range
For Each cell In Range("B1:B1000")
If Len(cell.Text) = 0 Then
If rng Is Nothing Then
Set rng = cell
Else
Set rng = Union(rng, cell)
End If
End If
Next
rng.EntireRow.Hidden = True
End Sub