VBA -excel --遍历行

Sub filter1()
Rem MsgBox ("AAAAA")
Rem 1 get selected zone
Rem 2 loop rows and check column
Rem 3 if true then hide it

Dim pos, total

Rem 获取行数
total = Sheet1.UsedRange.Rows.Count

Rem 开始循环
For pos = 1 To Sheet1.UsedRange.Rows.Count
Dim tmpStr

Rem B 列示第二列
tmpStr = Cells(pos, 2)
If InStr(tmpStr, "其他") Then
Range(Cells(pos, 1), Cells(total, 1)).EntireRow.Hidden = True

Exit Sub
End If

Rem MsgBox (tmpStr)
Next


End Sub

原文地址:https://www.cnblogs.com/micro-chen/p/6150312.html