我正在尝试遍历我指定的列,如果该列中的一个单元格包含子字符串,如果隐藏了该单元所在的行。
此:
A B
aaaccc 456
adzass 46
ddamdd 784
sdadaz 789
会变成这样:
A B
aaaccc 456
ddamdd 784
到目前为止,这是我的代码:
Dim N As Long, i As Long
N = Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To N
If Cells(i, "B") Like "*KB*" Or Cells(i, "B") Like "*KZ*" Then
'' MsgBox Cells(i, "B").Value
Cells(i, "B").Row.Hidden
End If
Next i
我以为我可以通过Cells(i, "B").Row
来获取单元格的行,但它似乎没有返回它。
答案 0 :(得分:0)
Dim N As Long, i As Long
N = Cells(Rows.Count, "B").End(xlUp).Row
For i = 2 To N
If Cells(i, "A") Like "*z*" Then 'changed criteria
'MsgBox Cells(i, "A").Value
Rows(i).Hidden = True 'Use Rows(rowindex) to get the row object
End If
Next i
上面的代码可以解决问题。
一些事情: