copy rows to new worksheet on change of value

I need a macro that would take the value column A and upon a change it would copy each group to a new worksheet.  

ie
Apple
Apple
Apple
Pear
Pear
Pear
Orange
Orange

So all the apple rows would go to a new workbook called apple and all the pear rows would go to a new workbook called pear and all the orange rows would go a new workbook called orange. Also it would copy the first row as the headers for each file.

Thanks,
Montrof
LVL 1
montrofAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glenn RayExcel VBA DeveloperCommented:
I'm not sure what "change" you would expect or require to make this happen, but in the meantime, I've set up a workbook with a button to activate a subroutine that will sort on the values in column A and move all values in the related rows to new sheets.  Each sheet preserves the column headings on the source sheet and the sheet name will be the value from column A.  
Sub Split_To_Multiple_Sheets()
    Dim intLR As Long
    Dim c As Integer
    Dim rng As Range
    Dim cl As Object
    Dim strNewSh As String
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    intLR = Cells.SpecialCells(xlLastCell).Row
    
    Sheets("Master").Activate
    ActiveWorkbook.Worksheets("Master").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Master").Sort.SortFields.Add Key:=Range("A2:A" & intLR) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Master").Sort
        .SetRange Range("A1:Z" & intLR)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
    Set rng = Range("A2:A" & intLR)
    For Each cl In rng
        If cl.Value <> cl.Offset(1, 0).Value Then 'create sheet
            strNewSh = cl.Value
            Sheets.Add After:=Sheets(ActiveWorkbook.Sheets.Count)
            ActiveSheet.Name = strNewSh
            Sheets("Master").Activate
            Range("A1:Z1").Copy
            Sheets(strNewSh).Activate
            ActiveSheet.Paste
            Sheets("Master").Activate
            Range("A" & cl.Row - c & ":Z" & cl.Row).Copy
            Sheets(strNewSh).Activate
            Range("A2").Select
            ActiveSheet.Paste
            Range("A1:Z1").EntireColumn.AutoFit
            Application.CutCopyMode = False
            Range("A2").Select
            Sheets("Master").Activate
            c = 0
        Else
            c = c + 1
        End If
    Next cl
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    MsgBox "Done."
End Sub

Open in new window


For simplicity, I've limited this to columns A through Z; if you need something dynamic - or more columns - let me know.

Regards,
-Glenn
EE-SplitMultipleSheets.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.