Split Worksheet to Multiple Worksheets

markoakes

Active Member
Joined
Jan 5, 2004
Messages
325
I have a worksheet that has data in columns A to N. The Salesman’s number is in column A and I need to split this first worksheet in to separate worksheets in the same workbook for each salesman.
 
Maybe this

Code:
Sub deviceNewSheet()
Dim LastRow As Long, LastCol As Integer, i As Long, iStart As Long, iEnd As Long
Dim ws As Worksheet
Application.ScreenUpdating = False
With ActiveSheet
    LastRow = .Cells(Rows.Count, "U").End(xlUp).Row
    LastCol = .Cells(10, Columns.Count).End(xlToLeft).Column
    .Range(.Cells(10, 2), .Cells(LastRow, LastCol)).Sort Key1:=.Range("U10"), Order1:=xlAscending, _
        Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    iStart = 2
    For i = 2 To LastRow
        If .Range("U" & i).Value <> .Range("U" & i + 1).Value Then
            iEnd = i
            Sheets.Add after:=Sheets(Sheets.Count)
            Set ws = ActiveSheet
            On Error Resume Next
            ws.Name = .Range("U" & iStart).Value
            On Error GoTo 0
            .Range(.Cells(1, 1), .Cells(10, LastCol)).Copy Destination:=ws.Range("A1")
            With ws.Rows("1:10")
                .HorizontalAlignment = xlCenter
                With .Font
                    .ColorIndex = 5
                    .Bold = True
                End With
            End With
            .Range(.Cells(iStart, 1), .Cells(iEnd, LastCol)).Copy Destination:=ws.Range("A11")
            iStart = iEnd + 1
        End If
    Next i
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
VoG,
You are the greatest. It is still doing some funny things like the first new sheet made is the information from rows 5-8.
Second sheet is titled Location which is value for "U9" and a header, also gives first row of information.

All new sheets carry the first row values at the top which is valued as location "Boiler" and the new sheet for "RO/PROCESS WATER" still has a standard sheet name, will try to change values and see what happens. It is a far better thing then I could have ever come up with and you deserve as many kudos as can get for getting me this far. If you don't have any more time to spend on this I understand and will try to straighten out the glitches. Nice touch the blue "5" by the way.

I do appreciate all your help in this. I am learning but I can't even dim row column yet. Using if statements. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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