PC Review


Reply
Thread Tools Rate Thread

Autofilter on Multiple Worksheets

 
 
Graham
Guest
Posts: n/a
 
      19th Feb 2009
Hi

I have the following code which will autofilter data based on a cell value
on another sheet.

What I would like to achieve is to filter data on all sheets with a name
beginning with DATA e.g. DATA, DATAJAN, DATAFEB etc.

Can this be achieved with a wildcard somehow?


Dim WB As Workbook
Dim SH1 As Worksheet
Dim SH2 As Worksheet
Dim rng As Range
Dim sStr As String

Set WB = ActiveWorkbook
Set SH1 = WB.Sheets("Insurer")
Set SH2 = WB.Sheets("DATA")

sStr = SH1.Range("E2").Value


Worksheets("DATA").Select
ActiveSheet.AutoFilterMode = False
Range("A1").AutoFilter
Range("A1").AutoFilter Field:=1, Criteria1:=sStr



thanks in advance

Graham
 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      19th Feb 2009
Use the worksheets collection and test the sheet name

e.g.

Dim wS as Worksheet
For Each wS in Worksheets
If Left(wS.Name, 4) = "DATA" then
' your code to apply the filter
End If
Next

--

Regards,
Nigel
(E-Mail Removed)



"Graham" <(E-Mail Removed)> wrote in message
news:6C9E1BC6-2DB8-49F4-A9A3-(E-Mail Removed)...
> Hi
>
> I have the following code which will autofilter data based on a cell value
> on another sheet.
>
> What I would like to achieve is to filter data on all sheets with a name
> beginning with DATA e.g. DATA, DATAJAN, DATAFEB etc.
>
> Can this be achieved with a wildcard somehow?
>
>
> Dim WB As Workbook
> Dim SH1 As Worksheet
> Dim SH2 As Worksheet
> Dim rng As Range
> Dim sStr As String
>
> Set WB = ActiveWorkbook
> Set SH1 = WB.Sheets("Insurer")
> Set SH2 = WB.Sheets("DATA")
>
> sStr = SH1.Range("E2").Value
>
>
> Worksheets("DATA").Select
> ActiveSheet.AutoFilterMode = False
> Range("A1").AutoFilter
> Range("A1").AutoFilter Field:=1, Criteria1:=sStr
>
>
>
> thanks in advance
>
> Graham


 
Reply With Quote
 
Graham
Guest
Posts: n/a
 
      19th Feb 2009
Thanks for your help Nigel

I understand your method for selecting relevant sheets but I'm having
problems applying it to the existing code

The new code below is filtering data only on the active sheet, I'm guessing
it has something to do with < ActiveSheet.AutoFilterMode = False>

Any ideas?

Dim WB As Workbook
Dim SH1 As Worksheet
Dim SH2 As Worksheet
Dim rng As Range
Dim sStr As String
Dim wS As Worksheet

Set WB = ActiveWorkbook
Set SH1 = WB.Sheets("Insurer")
Set SH2 = WB.Sheets("DATA")

sStr = SH1.Range("E2").Value


For Each wS In Worksheets
If Left(wS.Name, 4) = "DATA" Then

ActiveSheet.AutoFilterMode = False
Range("A1").AutoFilter
Range("A1").AutoFilter Field:=1, Criteria1:=sStr

End If



thanks
Graham

"Nigel" wrote:

> Use the worksheets collection and test the sheet name
>
> e.g.
>
> Dim wS as Worksheet
> For Each wS in Worksheets
> If Left(wS.Name, 4) = "DATA" then
> ' your code to apply the filter
> End If
> Next
>
> --
>
> Regards,
> Nigel
> (E-Mail Removed)
>
>
>
> "Graham" <(E-Mail Removed)> wrote in message
> news:6C9E1BC6-2DB8-49F4-A9A3-(E-Mail Removed)...
> > Hi
> >
> > I have the following code which will autofilter data based on a cell value
> > on another sheet.
> >
> > What I would like to achieve is to filter data on all sheets with a name
> > beginning with DATA e.g. DATA, DATAJAN, DATAFEB etc.
> >
> > Can this be achieved with a wildcard somehow?
> >
> >
> > Dim WB As Workbook
> > Dim SH1 As Worksheet
> > Dim SH2 As Worksheet
> > Dim rng As Range
> > Dim sStr As String
> >
> > Set WB = ActiveWorkbook
> > Set SH1 = WB.Sheets("Insurer")
> > Set SH2 = WB.Sheets("DATA")
> >
> > sStr = SH1.Range("E2").Value
> >
> >
> > Worksheets("DATA").Select
> > ActiveSheet.AutoFilterMode = False
> > Range("A1").AutoFilter
> > Range("A1").AutoFilter Field:=1, Criteria1:=sStr
> >
> >
> >
> > thanks in advance
> >
> > Graham

>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Feb 2009
For Each wS In Worksheets
If Left(wS.Name, 4) = "DATA" Then
ws.AutoFilterMode = False
ws.Range("A1").AutoFilter
ws.Range("A1").AutoFilter Field:=1, Criteria1:=sStr
End If
....

Graham wrote:
>
> Thanks for your help Nigel
>
> I understand your method for selecting relevant sheets but I'm having
> problems applying it to the existing code
>
> The new code below is filtering data only on the active sheet, I'm guessing
> it has something to do with < ActiveSheet.AutoFilterMode = False>
>
> Any ideas?
>
> Dim WB As Workbook
> Dim SH1 As Worksheet
> Dim SH2 As Worksheet
> Dim rng As Range
> Dim sStr As String
> Dim wS As Worksheet
>
> Set WB = ActiveWorkbook
> Set SH1 = WB.Sheets("Insurer")
> Set SH2 = WB.Sheets("DATA")
>
> sStr = SH1.Range("E2").Value
>
>
> For Each wS In Worksheets
> If Left(wS.Name, 4) = "DATA" Then
>
> ActiveSheet.AutoFilterMode = False
> Range("A1").AutoFilter
> Range("A1").AutoFilter Field:=1, Criteria1:=sStr
>
> End If
>
> thanks
> Graham
>
> "Nigel" wrote:
>
> > Use the worksheets collection and test the sheet name
> >
> > e.g.
> >
> > Dim wS as Worksheet
> > For Each wS in Worksheets
> > If Left(wS.Name, 4) = "DATA" then
> > ' your code to apply the filter
> > End If
> > Next
> >
> > --
> >
> > Regards,
> > Nigel
> > (E-Mail Removed)
> >
> >
> >
> > "Graham" <(E-Mail Removed)> wrote in message
> > news:6C9E1BC6-2DB8-49F4-A9A3-(E-Mail Removed)...
> > > Hi
> > >
> > > I have the following code which will autofilter data based on a cell value
> > > on another sheet.
> > >
> > > What I would like to achieve is to filter data on all sheets with a name
> > > beginning with DATA e.g. DATA, DATAJAN, DATAFEB etc.
> > >
> > > Can this be achieved with a wildcard somehow?
> > >
> > >
> > > Dim WB As Workbook
> > > Dim SH1 As Worksheet
> > > Dim SH2 As Worksheet
> > > Dim rng As Range
> > > Dim sStr As String
> > >
> > > Set WB = ActiveWorkbook
> > > Set SH1 = WB.Sheets("Insurer")
> > > Set SH2 = WB.Sheets("DATA")
> > >
> > > sStr = SH1.Range("E2").Value
> > >
> > >
> > > Worksheets("DATA").Select
> > > ActiveSheet.AutoFilterMode = False
> > > Range("A1").AutoFilter
> > > Range("A1").AutoFilter Field:=1, Criteria1:=sStr
> > >
> > >
> > >
> > > thanks in advance
> > >
> > > Graham

> >
> >


--

Dave Peterson
 
Reply With Quote
 
Graham
Guest
Posts: n/a
 
      19th Feb 2009
Nigel/Dave

Thanks very much for your help
Now all that's left for me is to adapt all the formulas to subtotals

"Dave Peterson" wrote:

> For Each wS In Worksheets
> If Left(wS.Name, 4) = "DATA" Then
> ws.AutoFilterMode = False
> ws.Range("A1").AutoFilter
> ws.Range("A1").AutoFilter Field:=1, Criteria1:=sStr
> End If
> ....
>
> Graham wrote:
> >
> > Thanks for your help Nigel
> >
> > I understand your method for selecting relevant sheets but I'm having
> > problems applying it to the existing code
> >
> > The new code below is filtering data only on the active sheet, I'm guessing
> > it has something to do with < ActiveSheet.AutoFilterMode = False>
> >
> > Any ideas?
> >
> > Dim WB As Workbook
> > Dim SH1 As Worksheet
> > Dim SH2 As Worksheet
> > Dim rng As Range
> > Dim sStr As String
> > Dim wS As Worksheet
> >
> > Set WB = ActiveWorkbook
> > Set SH1 = WB.Sheets("Insurer")
> > Set SH2 = WB.Sheets("DATA")
> >
> > sStr = SH1.Range("E2").Value
> >
> >
> > For Each wS In Worksheets
> > If Left(wS.Name, 4) = "DATA" Then
> >
> > ActiveSheet.AutoFilterMode = False
> > Range("A1").AutoFilter
> > Range("A1").AutoFilter Field:=1, Criteria1:=sStr
> >
> > End If
> >
> > thanks
> > Graham
> >
> > "Nigel" wrote:
> >
> > > Use the worksheets collection and test the sheet name
> > >
> > > e.g.
> > >
> > > Dim wS as Worksheet
> > > For Each wS in Worksheets
> > > If Left(wS.Name, 4) = "DATA" then
> > > ' your code to apply the filter
> > > End If
> > > Next
> > >
> > > --
> > >
> > > Regards,
> > > Nigel
> > > (E-Mail Removed)
> > >
> > >
> > >
> > > "Graham" <(E-Mail Removed)> wrote in message
> > > news:6C9E1BC6-2DB8-49F4-A9A3-(E-Mail Removed)...
> > > > Hi
> > > >
> > > > I have the following code which will autofilter data based on a cell value
> > > > on another sheet.
> > > >
> > > > What I would like to achieve is to filter data on all sheets with a name
> > > > beginning with DATA e.g. DATA, DATAJAN, DATAFEB etc.
> > > >
> > > > Can this be achieved with a wildcard somehow?
> > > >
> > > >
> > > > Dim WB As Workbook
> > > > Dim SH1 As Worksheet
> > > > Dim SH2 As Worksheet
> > > > Dim rng As Range
> > > > Dim sStr As String
> > > >
> > > > Set WB = ActiveWorkbook
> > > > Set SH1 = WB.Sheets("Insurer")
> > > > Set SH2 = WB.Sheets("DATA")
> > > >
> > > > sStr = SH1.Range("E2").Value
> > > >
> > > >
> > > > Worksheets("DATA").Select
> > > > ActiveSheet.AutoFilterMode = False
> > > > Range("A1").AutoFilter
> > > > Range("A1").AutoFilter Field:=1, Criteria1:=sStr
> > > >
> > > >
> > > >
> > > > thanks in advance
> > > >
> > > > Graham
> > >
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Feb 2009
If you're inserting the =subtotal()'s using data|subtotals, then you may not
want to use autofilter with this.

Try it manually first and you'll see what I mean.

Graham wrote:
>
> Nigel/Dave
>
> Thanks very much for your help
> Now all that's left for me is to adapt all the formulas to subtotals
>
> "Dave Peterson" wrote:
>
> > For Each wS In Worksheets
> > If Left(wS.Name, 4) = "DATA" Then
> > ws.AutoFilterMode = False
> > ws.Range("A1").AutoFilter
> > ws.Range("A1").AutoFilter Field:=1, Criteria1:=sStr
> > End If
> > ....
> >
> > Graham wrote:
> > >
> > > Thanks for your help Nigel
> > >
> > > I understand your method for selecting relevant sheets but I'm having
> > > problems applying it to the existing code
> > >
> > > The new code below is filtering data only on the active sheet, I'm guessing
> > > it has something to do with < ActiveSheet.AutoFilterMode = False>
> > >
> > > Any ideas?
> > >
> > > Dim WB As Workbook
> > > Dim SH1 As Worksheet
> > > Dim SH2 As Worksheet
> > > Dim rng As Range
> > > Dim sStr As String
> > > Dim wS As Worksheet
> > >
> > > Set WB = ActiveWorkbook
> > > Set SH1 = WB.Sheets("Insurer")
> > > Set SH2 = WB.Sheets("DATA")
> > >
> > > sStr = SH1.Range("E2").Value
> > >
> > >
> > > For Each wS In Worksheets
> > > If Left(wS.Name, 4) = "DATA" Then
> > >
> > > ActiveSheet.AutoFilterMode = False
> > > Range("A1").AutoFilter
> > > Range("A1").AutoFilter Field:=1, Criteria1:=sStr
> > >
> > > End If
> > >
> > > thanks
> > > Graham
> > >
> > > "Nigel" wrote:
> > >
> > > > Use the worksheets collection and test the sheet name
> > > >
> > > > e.g.
> > > >
> > > > Dim wS as Worksheet
> > > > For Each wS in Worksheets
> > > > If Left(wS.Name, 4) = "DATA" then
> > > > ' your code to apply the filter
> > > > End If
> > > > Next
> > > >
> > > > --
> > > >
> > > > Regards,
> > > > Nigel
> > > > (E-Mail Removed)
> > > >
> > > >
> > > >
> > > > "Graham" <(E-Mail Removed)> wrote in message
> > > > news:6C9E1BC6-2DB8-49F4-A9A3-(E-Mail Removed)...
> > > > > Hi
> > > > >
> > > > > I have the following code which will autofilter data based on a cell value
> > > > > on another sheet.
> > > > >
> > > > > What I would like to achieve is to filter data on all sheets with a name
> > > > > beginning with DATA e.g. DATA, DATAJAN, DATAFEB etc.
> > > > >
> > > > > Can this be achieved with a wildcard somehow?
> > > > >
> > > > >
> > > > > Dim WB As Workbook
> > > > > Dim SH1 As Worksheet
> > > > > Dim SH2 As Worksheet
> > > > > Dim rng As Range
> > > > > Dim sStr As String
> > > > >
> > > > > Set WB = ActiveWorkbook
> > > > > Set SH1 = WB.Sheets("Insurer")
> > > > > Set SH2 = WB.Sheets("DATA")
> > > > >
> > > > > sStr = SH1.Range("E2").Value
> > > > >
> > > > >
> > > > > Worksheets("DATA").Select
> > > > > ActiveSheet.AutoFilterMode = False
> > > > > Range("A1").AutoFilter
> > > > > Range("A1").AutoFilter Field:=1, Criteria1:=sStr
> > > > >
> > > > >
> > > > >
> > > > > thanks in advance
> > > > >
> > > > > Graham
> > > >
> > > >

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
autofilter linked in different worksheets Ross in Oz Microsoft Excel Misc 2 20th Feb 2010 09:15 PM
Autofilter in protected worksheets JL Microsoft Excel Worksheet Functions 0 27th Oct 2008 01:51 AM
Linking Worksheets and Autofilter =?Utf-8?B?YmlzY3VpdHNtb20=?= Microsoft Excel Misc 3 4th Aug 2005 03:26 PM
Can I autofilter across multiple worksheets? =?Utf-8?B?ZGNIaWxs?= Microsoft Excel Programming 0 16th Jun 2005 07:44 PM
Autofilter across Worksheets Talon Microsoft Excel Programming 1 17th Dec 2003 10:19 PM


Features
 

Advertising
 

Newsgroups
 


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