我写了一段,测试可用。代码如下: 其实核心的代码就是中间 For........Next i 加上它前面那三行一共六行。开头与结尾那些是为了提高在大量数据(数千条以上时)处理时的效率。
Sub 隐藏() Dim tmpStr As String, i As Long, j As Integer Dim Title As Integer, calcState, displayPageBreakState calcState = Application.Calculation displayPageBreakState = ActiveSheet.DisplayPageBreaks Application.ScreenUpdating = False Application.Calculation = xlCalculationManual ActiveSheet.DisplayPageBreaks = False
Title = 1 '标题的最大行,从此行以下开始筛选 tmpStr = ActiveCell.Value j = ActiveCell.Column() For i = Title + 1 To Range(A1).SpecialCells(xlLastCell).Row() If Cells(i, j).Value tmpStr Then Cells(i, j).EntireRow.Hidden = True Next i Cells(Title + 1, j).Select
Application.ScreenUpdating = True Application.Calculation = calcState ActiveSheet.DisplayPageBreaks = displayPageBreakState End Sub