隐藏单元格为空时的行excel(更快的方法)

我看了一些文章和build议,并提出了一个解决我的问题。

文章更快的方式来隐藏空行build议使用切换前的Application.ScreenUpdating循环为false,之后为true。 它稍微加快了脚本,但对于10.000行还是需要相当长的一段时间。

要求:

如果行中的第一个单元格为空,则隐藏完整的行,它需要向下兼容到2013以外的其他excel版本

目前的工作解决scheme为Excel 2013

  Application.ScreenUpdating = False Dim s As String For i = 1 To range("A1:A10000").Count s = i & ":" & i If IsEmpty(Cells(i, 1).Value) Then Rows(s).Select Selection.EntireRow.Hidden = True End If Next Application.ScreenUpdating = True 

不幸的是,我不知道表单中有多less数据,它可以包含less于10.000的数据,在我的示例中使用的数据甚至更多。 当我运行脚本它工作正常,但需要相当一段时间10.000行和年龄为表中的所有单元格。

当工作簿被加载时,macros会自动运行(不知道怎么做,或者哈哈)

 Dim rngBlnk As Range On Error Resume Next 'in case no blanks are present... Set rngBlnk = Range("A1:A100000").SpecialCells(xlCellTypeBlanks) On Error GoTo 0 If Not rngBlnk Is Nothing Then Debug.Print rngBlnk.Address() rngBlnk.EntireRow.Hidden = True End If 

正如在我的评论和这篇文章: 更快的方式来隐藏空行,并感谢@tigeravatar指出。 我使用了以下在我的场景中工作的代码:

 Range("A1:A10000").AutoFilter 1, "<>", , , False 

select过程需要时间,在隐藏行之前不需要select行。 尝试下面的变化…

 Application.ScreenUpdating = False Dim s As String For i = 1 To range("A1:A10000").Count s = i & ":" & i If IsEmpty(Cells(i, 1).Value) Then Rows(s).EntireRow.Hidden = True End If Next Application.ScreenUpdating = True