1

I work with sheets named; Rev00, Rev01, Rev02 etc - among other sheets in my workbook.

It would be very helpful (in order to compare the sub-summaries of different revisions) to set the exact same multiple-filter - as set in active sheet - in only all sheets beginning with "Rev".

This action should most wanted be activated by double Click in Range("A1") or somewhere like that (I dont want button on this one).

If possible next double Click in Range("A1") should reset filters.

Sub Test()
    Dim ws As Worksheet, str As String        
    For Each ws In Worksheets            
            str = Left(ws.Name, 3)                    
                If str = "Rev" Then                        
                    ' set filter as in active.sheet                    
                End If
     Next ws
End Sub

... and I am stuck .... will anyone guide me on this?

Community
  • 1
  • 1

1 Answers1

1

Yes it is possible. :) Here is a basic sample on how it should work.

Sub Test()
    Dim ws As Worksheet, str As String

    For Each ws In Worksheets
        str = Left(ws.Name, 3)
        If UCase(str) = "REV" Then
            With ws
                '~~> Remove any filters
                .AutoFilterMode = False

                With <YOUR RANGE>
                    .AutoFilter Field:=<RELEVANT FIELD>, _
                                Criteria1:=<YOUR CRITERIA>

                    '
                    '~~> Rest of the code
                    '
                End With

                '~~> Remove any filters
                '.AutoFilterMode = False
            End With
        End If
    Next ws
End Sub

Here you can see Autofilter in action :)

To call the above code by clicking Range A1, you can use the Worksheet_BeforeDoubleClick event.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        '
        '~~> Your code goes here
        '
        Cancel = True
    End If
End Sub

Regarding your query about making Range A1 respond as an ON/OFF switch, you can use a boolean variable s shown HERE

Community
  • 1
  • 1
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250