Autofilter for multiple sheets

A

Agustus

Hi,

I have a macro below to turn the autofilter "on" for multiple selected
sheets but it generated error. Please advise.

Sub auto_filter_all_sheets()
Dim ws As Worksheet
Application.ScreenUpdating = False

sAddress = Selection.Address
For Each ws In ActiveWindow.SelectedSheets
ws.Activate
If sAddress > "" Then ws.Range(sAddress).Select
Selection.AutoFilter
Next ws
Application.ScreenUpdating = True
End Sub

TIA.
 
T

Tom Ogilvy

Sub auto_filter_all_sheets()
Dim ws As Worksheet
Application.ScreenUpdating = False

if selection.Rows.count < 3 then exit sub
sAddress = Selection.Address
For Each ws In ActiveWindow.SelectedSheets
ws.Range(sAddress).AutoFilter
Next ws
Application.ScreenUpdating = True
End Sub
 
H

halimnurikhwan

Hi Tom,
think Tia needs to return the filter,
assumed the autofilter is already checked up !,
but don't know why she needs to achieve for ?
perhaps :
ws.Range(sAddress).AutoFilter field:="Shomething"
if only turned on or checked up the autofilter, i think no need
do it by automation !?, it wil be more complicating if do it by
automation!
is that r8?

Please reply ..., just guess

Rgds,
halim

Tom Ogilvy menuliskan:
 
A

Agustus

Thank very much, Tom.. It works. The reason is that I have 10+ sheets
and need to turn the filter on for each sheet. With multiple sheets
selected, the menu does not allow autofilter option.

Best regards,
Agustus
 

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