VBA Autofilter to Clear cells in Field2 that match Field1 criteria

Giga_Me

New Member
Joined
Jun 14, 2011
Messages
15
I just started using autofilter to avoid looping as much in my code but am hoping someone can help me to understand how I can use the autofilter in VBA to, for example, clear a cell in Field2 where the criteria in Field2 and Field1 match.

Would I use offset somehow like (this example will obviously not work :) )

Code:
Cells(1, 1).AutoFilter field:=2, Criteria1:="=" & Cells.Offset(0, -1)
rng.SpecialCells(xlCellTypeVisible).Clear

Thanks,

Giga_Me
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
That's not how Autofilter works. You would need to add a new column temporarily with a "test" formula in it, thus marking all the rows for clearing.

So in M2 you could put this to test A2 and B2:

=A2=B2

Copy that down, then filter that column for TRUE. Then clear the visible cells in A or B, whichever it is you're trying to do.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top