Autofiltering data across sheets

basicallyawesome

New Member
Joined
Jul 10, 2018
Messages
29
Office Version
  1. 365
Let's say I have a workbook, Sheet 1 is called "Birds" and has everything you could ever want to know about birds. Column E is where I enter the type of bird in non-scientific terms, like Crow, Blackbird, Raven, Magpie, etc. These values are recurring so I could have several records for crows, and the other birds. I enter the data using a userform. When I am done I want to be able to hit a command button to kibosh the userform AND automatically filter the records into their own sheets within the workbook, named after each bird. Is this possible? How can I make this happen? Thank you!!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
So what do you want to end up with?
- a workbook comprising the original worksheet plus s worksheet for every unique value that appears in column E, containing the same columns as the original worksheet
 
Upvote 0
Try this
- amend Data to match your actual sheet name

In standard module

Code:
Sub BirdSheets()
    Application.ScreenUpdating = False
    Dim main As Worksheet, ws As Worksheet, sky As Range, bird As Variant, flight As Range
    Dim menagerie As New Collection
    Set main = Sheets("[COLOR=#ff0000]Data[/COLOR]")
    Set sky = main.Range("A1").CurrentRegion
    Set flight = main.Range("E2").Resize(sky.Rows.Count - 1)

    For Each bird In flight
        On Error Resume Next
        menagerie.Add CStr(bird), CStr(bird)
    Next bird
    
    For Each bird In menagerie
        DeleteSheet (bird)
        main.ShowAllData
        sky.AutoFilter Field:=5, Criteria1:=bird
        Set ws = Sheets.Add(After:=ActiveSheet)
        ws.Name = bird
        sky.Copy ws.Range("A1")
    Next bird
    Application.ScreenUpdating = True
End Sub
Code:
Private Sub DeleteSheet(SheetName As String)
    Application.DisplayAlerts = False
    On Error Resume Next
    Sheets(SheetName).Delete
    Application.DisplayAlerts = True
End Sub

To close the userform and run the code...
In Userform code
Code:
Private Sub [COLOR=#ff0000]CommandButton1[/COLOR]_Click()
    Unload Me
    Call BirdSheets
End Sub
 
Last edited:
Upvote 0
Sorry for the delay, I finally had a chance to implement it; it worked and did exactly what I needed. Thank you so much!!
 
Upvote 0
@ Yongle:-

I like the variable names that you have used. Very clever! :lol:

I'm sure that the OP appreciates it also.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,224,943
Messages
6,181,922
Members
453,071
Latest member
Gizmo2024

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