我寫了一段,測試可用。程式碼如下:其實核心的程式碼就是中間 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 = displayPageBreakStateEnd Sub
我寫了一段,測試可用。程式碼如下:其實核心的程式碼就是中間 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 = displayPageBreakStateEnd Sub