Sub Group()
Dim arrList As Variant
Dim rng As Excel.Range
Dim rCell As Range
Dim N As Long
Set rng = Range(ActiveCell, ActiveCell.End(xlDown)).Select
arrList = Array("TP001P*")
For Each rCell In rng.Cells
For N = LBound(arrList) To UBound(arrList)
If VBA.InStr(1, rCell.Value, arrList(N), vbTextCompare) > 0 Then
rCell.EntireRow.Hidden = True
Exit For
End If
Next 'N
Next 'rCell
End Sub
要“按前缀”过滤,请使用 Like 功能。然后通过将所有发现添加到一个范围内,您可以将所有行隐藏在一起
Option Explicit
Sub Group()
Dim arrList As Variant, rng As Range, rCell As Range, N As Long
Dim lb As Long, ub As Long, toHide As Range
Set rng = Range(ActiveCell, ActiveCell.End(xlDown))
arrList = Array("TP001P*")
lb = LBound(arrList)
ub = UBound(arrList)
For Each rCell In rng.Cells
For N = lb To ub
If rCell.Value Like arrList(N) Then
If toHide Is Nothing Then
Set toHide = rCell
Else
Set toHide = Union(toHide, rCell)
End If
Exit For
End If
Next
Next
If Not toHide Is Nothing Then toHide.EntireRow.Hidden = True
End Sub