Splitwork Sheet By Value Macro HELP

AldoRaine

New Member
Joined
Sep 22, 2011
Messages
3
Hello,

I need to split a worksheet into new workshets in the same workbook using customer names in column D which includes subtotals. However, the macro i am using splits the customer name and customer subtotal into different sheets as the customer name now contains "total" so the macro doesn't recognize this is the same customer.

E.G

Customer name
Kwik Fit
Kwit Fit Subtotal
Mail Marketing
Mail Marketing Subtotal

I need the macro to split the above customer names so that the customer name including the subtotal gets split into a new worksheet AND the new worksheet is named after the customer name.

I am aware their are add ins for such tasks but i am using this at work and cannot install any files.

http://www.mrexcel.com/forum/showthread.php?t=396069




Sub Lapta() Dim lastrow As Long, LastCol As Integer, i As Long, iStart As Long, iEnd As Long Dim ws As Worksheet, r As Range, iCol As Integer, t As Date On Error Resume Next Set r = Application.InputBox("Click in the column to extract by", Type:=8) On Error GoTo 0 If r Is Nothing Then Exit Sub iCol = r.Column t = Now Application.ScreenUpdating = False With ActiveSheet lastrow = .Cells(Rows.Count, "A").End(xlUp).Row LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column .Range(.Cells(2, 1), Cells(lastrow, LastCol)).Sort Key1:=Cells(2, iCol), Order1:=xlAscending, _ Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom iStart = 2 For i = 2 To lastrow If .Cells(i, iCol).Value <> .Cells(i + 1, iCol).Value Then iEnd = i Sheets.Add after:=Sheets(Sheets.Count) Set ws = ActiveSheet On Error Resume Next ws.Name = .Cells(iStart, iCol).Value On Error GoTo 0 ws.Range(Cells(1, 1), Cells(1, LastCol)).Value = .Range(.Cells(1, 1), .Cells(1, LastCol)).Value .Range(.Cells(iStart, 1), .Cells(iEnd, LastCol)).Copy Destination:=ws.Range("A2") iStart = iEnd + 1 End If Next i End With Application.CutCopyMode = False Application.ScreenUpdating = True MsgBox "Completed in " & Format(Now - t, "hh:mm:ss.00"), vbInformation End Sub</pre>
I appreciate any help anyone can give - i'm currently trying to learn VBA but this one is a tough nut to crack! Need some help :)

Thanks in advance
Aldo
 
Last edited:

Forum statistics

Threads
1,226,850
Messages
6,193,354
Members
453,790
Latest member
yassinosnoo1

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