如果同一行中col A和B的值相同,如5 5或22 22 然后我想隐藏整行或不过滤那些行。
sub myExample
dim filter_Z as range, rowW as range, COLA as range, COLB as range
dim last_row as long
Set filter_Z = Sheets(1).Range("A1" & last_row)
'
For Each rowW In filter_Z.SpecialCells(xlCellTypeVisible)
'
COLA = ActiveWorkbook.Worksheets("MySheets1").Range("A" & rowW.Row).Value
COLB = ActiveWorkbook.Worksheets("MySheets1").").Range("B" & rowW.Row).Value
If COLA=COLB Then rowW.EntireRow.Hidden = True
Next rowW
end sub
答案 0 :(得分:0)
这至少应该指向正确的方向:
Option Explicit
Sub hideRows()
Application.ScreenUpdating = False
Dim sh As Worksheet, rw As Range
Set sh = ActiveSheet
For Each rw In sh.Rows
If sh.Cells(rw.Row, 1).Value And sh.Cells(rw.Row, 2).Value = "" Then
Exit For
End If
If sh.Cells(rw.Row, 1).Value = sh.Cells(rw.Row, 2).Value Then
rw.EntireRow.Hidden = True
End If
Next rw
Application.ScreenUpdating = True
End Sub