Hi everyone!
Brand new here so feel free to let me know if there is any etiquette that I missed. I am trying to create a macro that will take data ("Total Summary") and split it into separate worksheets based on unique values in one of the data columns. I found a YouTube video in my search on how to do this and tried to replicate it with a few adjustments. Can't post the link because I'm too new, but it's called "Split a Master Spreadsheet into Multiple Sheets with 1 click - VBA for Beginner" by Caripros HR Analytics.
Below is the code I ended up with, as well as the basic steps I tried to accomplish.- Copy the data from "Total Summary" tab into the "Season Payout Form" tab - The reason I decided to put it on a different spreadsheet was because I was planning on adding various formatting/formulas to it later and wanted to preserve a clean data dump tab.
- For each cell in this list of unique values I have on a separate sheet ("Project List"), copy the "Season Payout Form" tab into another spreadsheet
- Name the new spreadsheet after the cell value
- Filter the new spreadsheet data by everything that is not the cell value and delete it
- Show all data to display what is left, which should just be the line items related to the cell value
- Go to the next cell
- Rinse and repeat until complete
When I ran the macro, I encountered "Run-Time Error 9" on the line where it starts referencing the new sheet to filter the data. I've tried figuring out how to debug it, but to no avail. Any insight as to how to fix this? All I know is that it has something to do with not being able to find the sheet in question. Also, if you have any suggestions about a better way to do this, let me know! I thought about filtering the data and then copying it, but I wasn't able to find any ready-to-use macro that I could understand enough to adjust. Thanks in advance! Also, dummy spreadsheet attached, in case it helps.
Sub SeasonSplit()
Dim TotalSummary As Range
Dim SeasonPayout As Range
Dim ProjectList As Range
Set TotalSummary = Worksheets("Total Summary").Range("A3", Range("A3").End(xlDown).End(xlToRight))
Set SeasonPayout = Worksheets("Season Payout Form").Range("A4")
Set ProjectList = Range("ProjectList")
For Each cell In ProjectList
TotalSummary.Copy SeasonPayout
Sheets("Season Payout Form").Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = cell.Value
With ActiveWorkbook.Sheets(cell.Value).Range("A4", Range("A4").End(xlDown).End(xlToRight))
.AutoFilter Field:=6, Criteria1:="<>" & cell.Value, Operator:=xlFilterValues
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
ActiveSheet.AutoFilter.ShowAllData
Next cell
End Sub
Bookmarks