我试图循环我指定的列,如果该列中的一个单元格包含子字符串,如果隐藏该单元格所在的行。
这个:
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
获得细胞行,但它似乎没有返回它。
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
上面的代码应该可以解决问题。
一些东西: