ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Filter Macro (https://www.excelbanter.com/excel-programming/379809-re-filter-macro.html)

PaulD

Filter Macro
 
"Dennis@Merlin" wrote in message
...
:I have a workbook with multiple worksheets and each WS has a different
number
: of rows. I'm trying to write a single macro that I can use with each WS
: indicidually to filter the data. Here's my code; but I get a Run-time
error
: '1004' ; Method Range of object '_Global' failed on the line before End
Sub.
:
: Sub FilterData()
: Dim MyRange As Range
: Range("E10").Activate
: Set MyRange = Range("E10", Cells(Rows.Count, 5).End(xlUp))
: Range("MyRange").AdvancedFilter Action:=xlFilterInPlace,
: CriteriaRange:=Range("E1:E2"), Unique:=False
: End Sub

I don't think you can Range("MyRange") since it is already a range. Also, I
deleted the activate since typically this is not needed but if you did want
it, then put it back.

Sub FilterData()
Dim MyRange As Range
Set MyRange = Range("E10", Cells(Rows.Count, 5).End(xlUp))
MyRange.AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:=Range("E1:E2"), Unique:=False
End Sub




All times are GMT +1. The time now is 06:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com