VBA to filter multiple sheets based on a cell on another sheet

Status
Not open for further replies.

lydytunes

New Member
Joined
Mar 16, 2011
Messages
38
I've been doing some digging and have found a few answers but nothing that does specifically what I'm trying to do. I have an excel file with over 10 sheets and four of these sheets I need to apply a filter to based on a selection made on another sheet. I'm currently using the code below, but I have to select each sheet in order for the filtering to work.

Private Sub Worksheet_Activate()
Unprotect Password:="notouch"
On Error Resume Next
Selection.AutoFilter Field:=2, Criteria1:=Sheets("Choose Your Department").Range("D3").Value
Protect Password:="notouch"
End Sub

I'm looking for a way to get the filtering to work so the users don't have to select each tab to make it happen. The filtered results are then being used on other tabs the users will be editing. Any help would be appreciated.

Thanks.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi,
Try following

Place in your worksheets (Choose Your Department) code page

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet
    If Target.Address = "$D$3" Then
        For Each ws In Worksheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4"))
            With ws
            .Unprotect Password:="notouch"
                If .AutoFilterMode Then .ShowAllData
                .Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:=Target.Value
            .Protect Password:="notouch"
           End With
        Next ws
    End If
End Sub

When value if cell D3 is changed, filter should be applied to specified sheets.

Change the sheet names shown in RED code applies to as required.

Hope helpful

Dave
 
Upvote 0
Dave,

Thanks for this code. I knew it was some type of Array wording but couldn't figure it out. This worked perfectly.
 
Upvote 0
Hi Dave - I have tried to replicate this and am failing - please can you advise when you have a minute?

 
Upvote 0
Hi Dave - I have tried to replicate this and am failing - please can you advise when you have a minute?

Duplicate to: VBA - filter multiple sheets based on cell ref

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top