Lets say you a 10000 row data dump which has atleast 30 types of unique values in a column. Now your task it to split this data into multiple sheets with these sheets being named based on the unique value.
Doing this task manually would take atleast 30 mins and is prone to human error.
So how do we do this using a macro. Here are the steps based on a hypothetical data.
Our data is below. For this exercise prepare something similar on your Excel.
Sub filter()Application.ScreenUpdating = FalseDim x As RangeDim rng As RangeDim last As LongDim sht As String'specify sheet name in which the data is stored which needs to be splitsht = "Macro 2"'choose the filter column in the following codelast = Sheets(sht).Cells(Rows.Count, "B").End(xlUp).RowSet rng = Sheets(sht).Range("B1:I" & last)
'N1 is the column where the code temporarily stores unique values of the "to-be-split" 'column from previous step, so specify a empty column
Sheets(sht).Range("B1:B" & last).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("N1"), Unique:=TrueFor Each x In Range([N2], Cells(Rows.Count, "N").End(xlUp))With rng.AutoFilter.AutoFilter Field:=1, Criteria1:=x.Value.SpecialCells(xlCellTypeVisible).CopySheets.Add(After:=Sheets(Sheets.Count)).Name = x.ValueActiveSheet.PasteEnd WithNext x' Turn off filterSheets(sht).AutoFilterMode = FalseWith Application.CutCopyMode = False.ScreenUpdating = TrueEnd WithEnd Sub
Once you have entered the above code. You can have a button/object linked with this code so that evey time you click the data is split based on the specified column into multiple sheets and with name of the sheet as per the unique value used to split.
If you need a copy of the excel file readymade, please email me at askme.kkhelps@gmail.com
Hope this helps!
Post a Comment
0Comments