Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Autofilter More than One Worksheet

I have a spreadsheet which has two worksheets, the first represents 6
months Jan to June and the second July to December. Each worksheet
has the same data in the first three columns (first name, surname,
teamname) I have autofilter set up to allow the user to filter either
their own record (by surname) or by their team. Unfortunately they
have to select this in each worksheet

Is there a way that the autofilter selected in worksheet one can be
automatically applied to worksheet two (and vice versa)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Autofilter More than One Worksheet

Right click on the sheet tab of the first sheet and select view code. Put
in this event.

This is an adaptation of some code posted by Debra Dalgleish

Change "Sheet2" to the name of the second sheet.

Private Sub Worksheet_Deactivate()
Dim i As Integer
Dim filt As Filter
Dim Op As Long
Dim rng As Range
Dim rng1 As Range

If Me.FilterMode = False Then
Exit Sub
End If
With Worksheets("Sheet2")
Set rng = Me.AutoFilter.Range
If .AutoFilterMode = False Then
.Range(rng.Address).AutoFilter
End If
If .FilterMode Then _
.ShowAllData
Set rng1 = .Range(rng.Address)
End With
i = 0
For Each filt In Me.AutoFilter.Filters
i = i + 1
If filt.On Then
On Error Resume Next
Op = filt.Operator
On Error GoTo 0

If Op = 0 Then
rng1.AutoFilter Field:=i, _
Criteria1:=filt.Criteria1
Else
rng1.AutoFilter Field:=i, _
Criteria1:=filt.Criteria1, Operator:=Op, _
Criteria2:=filt.Criteria2
End If

End If
Next

End Sub

--
Regards,
Tom Ogilvy


"David Mitchell" wrote in message
om...
I have a spreadsheet which has two worksheets, the first represents 6
months Jan to June and the second July to December. Each worksheet
has the same data in the first three columns (first name, surname,
teamname) I have autofilter set up to allow the user to filter either
their own record (by surname) or by their team. Unfortunately they
have to select this in each worksheet

Is there a way that the autofilter selected in worksheet one can be
automatically applied to worksheet two (and vice versa)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Autofilter More than One Worksheet

Many thanks, Tom (and Debra Dalgleish)

Put code in both sheets and works perfectly.

Kind regards

David A Mitchell
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
AUTOFILTER IN A PROTECTED WORKSHEET William Excel Discussion (Misc queries) 1 August 22nd 08 10:27 PM
autofilter into another worksheet [email protected] Excel Discussion (Misc queries) 1 July 27th 07 04:16 PM
Autofilter Data to separate worksheet squenson Excel Discussion (Misc queries) 1 July 26th 07 06:27 PM
Using Autofilter on a Protected Worksheet Brendan Vassallo Excel Discussion (Misc queries) 1 March 31st 06 01:08 PM
Autofilter - Link to 2nd worksheet? Kingsley H via OfficeKB.com Excel Worksheet Functions 1 August 18th 05 07:31 PM


All times are GMT +1. The time now is 12:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"