Create worksheets for each employee with records in my file

SandsB

Well-known Member
Joined
Feb 13, 2007
Messages
731
Office Version
  1. 365
Platform
  1. Windows
My file has up to 1,000 rows each day. There are about 15 volunteers and each of the rows of data lists the user ID of the volunteer responsible. One volunteer may have 50, another 200, another none on any particular day. And the volunteers may change for a while so a new guy might appear now and then.

If the volunteers' user ID's (ABC123, DEF456, etc) are in column D, how can a macro create a new file for each volunteer and contain just that volunteer's records without knowing the user IDs of the volunteers in advance?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
VBA Code:
Option Explicit

Sub Nits(): Dim r As Long, i As Long, wb As Workbook, EO As String, ws As Worksheet, K
Set ws = ActiveSheet: r = ws.Range("A1").CurrentRegion.Rows.Count
Application.ScreenUpdating = False
                    With CreateObject("Scripting.Dictionary")
                        For i = 2 To r: EO = ws.Cells(i, 4)
                        If Not .Exists(EO) Then .Item(EO) = i
                        Next i: K = .Keys()
                        For i = 0 To UBound(K)
        ws.Range("A1").CurrentRegion.AutoFilter Field:=4, Criteria1:=K(i)
        
                            Set wb = Workbooks.Add
        ws.UsedRange.SpecialCells(xlCellTypeVisible).Copy wb.Sheets(1).Range("A1")
                wb.SaveAs ws.Parent.Path & "/" & K(i) & i: wb.Close
        
        ws.Range("A1").CurrentRegion.AutoFilter

Next i
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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