Apply same filter to all sheets in a workbook

M

manfareed

Hi,

I am after a macro which filters by a particular name eg. Tyson in Column B
for all worksheets in a workbook.

I would be attaching this macro to a "macro" button so when the admin click
the button the sheets are filtered for Tyson. If they click another button
then the filter will apply to another name eg. ALI.

Please help with macro. I would record it but each month the sheet names and
number of sheets will vary.

Thanks,

Manir
 
J

joshuafandango

Hi Manir,

How's this do you?

Sub Filter_All_Sheets()
Dim WS As Object
For Each WS In Worksheets
WS.Range("A1:C10").AutoFilter Field:=2, Criteria1:="Tyson"
Next WS
End Sub

Change the Range, Field (2 = column B) & Criteria to suit

JF
 
D

Don Guillett

Should get you going.

Sub eachsht()
For i = 2 To Worksheets.Count
With Sheets(Sheets(i).Name)
MsgBox .Range("a1")
End With
Next i
End Sub
 
M

manfareed

Thanks JF ... just what I was after

Hi Manir,

How's this do you?

Sub Filter_All_Sheets()
Dim WS As Object
For Each WS In Worksheets
WS.Range("A1:C10").AutoFilter Field:=2, Criteria1:="Tyson"
Next WS
End Sub

Change the Range, Field (2 = column B) & Criteria to suit

JF
 
M

manfareed

Hi JF ,

How would I exclude the first worksheet. This is going to be a summary sheet
with macro button which the user will click to filter.

Thanks
 
M

manfareed

hi,

this is my final code but i get an error...run time error 91 ??

Sub Filter_All_Booth()
Dim WS As Object
If WS.Name <> "Summary" Then

For Each WS In Worksheets
WS.Range("A2:p50").AutoFilter Field:=2, Criteria1:="Booth"
Next WS

End If

End Sub

thx
 
D

Don Guillett

Sub Filter_All_Booth()
Dim WS As Object

For Each WS In Worksheets
If WS.Name <> "Summary" Then

WS.Range("A2:p50").AutoFilter Field:=2, Criteria1:="Booth"
end if
Next WS
End Sub
 
M

manfareed

Many Thanks ...its been an education.

Don Guillett said:
Sub Filter_All_Booth()
Dim WS As Object

For Each WS In Worksheets
If WS.Name <> "Summary" Then

WS.Range("A2:p50").AutoFilter Field:=2, Criteria1:="Booth"
end if
Next WS
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top