PC Review


Reply
Thread Tools Rate Thread

2 Autofilters

 
 
N1KO
Guest
Posts: n/a
 
      28th May 2009
Hi,

I have an table which is autofiltered on a worksheet.

I've just had to add another table on another worksheet and i want this one
to filter when i change the filter on the 1st sheet.

Is this possible in VBA?

Thanks in advance
 
Reply With Quote
 
 
 
 
Roger Govier
Guest
Posts: n/a
 
      28th May 2009
Hi

This solution uses a UDF created by Tom Ogilvy to find the criteria that
have been set on a Sheet's Autofilter
I used Sheet2 and Sheet3.
Adjust to suit your needs.

Sub Filtersame()
Dim setfilter As String
setfilter = ShowFilter(Sheets("Sheet2").Range("A1"))

Sheets("Sheet3").Select
Selection.AutoFilter Field:=1, Criteria1:=setfilter

End Sub

'Here is a user defined function that will display the criteria in a cell:
'created by Tom Ogilvy
Public Function ShowFilter(rng As Range)
Dim filt As Filter
Dim sCrit1 As String
Dim sCrit2 As String
Dim sop As String
Dim lngOp As Long
Dim lngOff As Long
Dim frng As Range
Dim sh As Worksheet
Set sh = rng.Parent
If sh.FilterMode = False Then
ShowFilter = "No Active Filter"
Exit Function
End If
Set frng = sh.AutoFilter.Range

If Intersect(rng.EntireColumn, frng) Is Nothing Then
ShowFilter = CVErr(xlErrRef)
Else
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
ShowFilter = "No Conditions"
Else
Set filt = sh.AutoFilter.Filters(lngOff)
On Error Resume Next
sCrit1 = filt.Criteria1
sCrit2 = filt.Criteria2
lngOp = filt.Operator
If lngOp = xlAnd Then
sop = " And "
ElseIf lngOp = xlOr Then
sop = " or "
Else
sop = ""
End If
ShowFilter = sCrit1 & sop & sCrit2
End If
End If
End Function


--
Regards
Roger Govier

"N1KO" <(E-Mail Removed)> wrote in message
news:39426AEA-5055-48E1-9912-(E-Mail Removed)...
> Hi,
>
> I have an table which is autofiltered on a worksheet.
>
> I've just had to add another table on another worksheet and i want this
> one
> to filter when i change the filter on the 1st sheet.
>
> Is this possible in VBA?
>
> Thanks in advance


 
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
AutoFilters =?Utf-8?B?Sm9saQ==?= Microsoft Excel Worksheet Functions 0 21st Mar 2006 12:23 AM
How to set up AutoFilters? =?Utf-8?B?TVMgU3V6YW5uZQ==?= Microsoft Excel Worksheet Functions 1 30th Jun 2005 03:53 AM
autofilters Diego Villaseñor Fernández Microsoft Excel Worksheet Functions 1 14th Jan 2005 02:29 AM
VBA and Autofilters Frank Haverkamp Microsoft Excel Programming 2 10th Jan 2004 01:53 AM
Userforms and autofilters - Autofilters don't seen to work with userform Microsoft Excel Programming 3 28th Aug 2003 05:42 PM


Features
 

Advertising
 

Newsgroups
 


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