Advance Filter and VBA

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
527
Hello,
I’m attempting to use the following lines to remove unwanted information in a range. It works well if the Sheet Name is selected at the time. If I don’t have the sheet selected, it fails to work.


I've been able to Set ranges with the Autofilter option and run from a differnt sheet tab but cannot get the Advance filter to work the same way.

Any ideas is appreciated.

Code:
Worksheets("Weekend_Details").Range("A1:H" & lastMWeend).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("AB1:AG4"), Unique:=False

    With Worksheets("Weekend_Details").Range("A1:H" & lastMWeend)
              Set rngWk = .Offset(1).SpecialCells(xlCellTypeVisible)
        rngWk.SpecialCells(12).EntireRow.Delete
    End With
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Russell Hauf

MrExcel MVP
Joined
Feb 10, 2002
Messages
1,611
So is there a reason you don't want to select the sheet first? I believe for the EntireRow.Delete to work, you need to be on that sheet. Most other times you don't need to select the sheet or range...
 

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
527
I guess it’s not a big deal to use the select command. I added it and it worked fine. Thank you.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,910
Messages
5,525,585
Members
409,651
Latest member
Quasar Hunter

This Week's Hot Topics

Top