Hi, charltonLee,
okay, I still believe that you should get the best results without using macros but here we go.
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
Choose Insert | Module
Where the cursor is flashing, choose Edit | Paste
To run the Excel VBA code:
Choose Tools | Macro | Macros
Select a macro in the list, and click the Run button
Sub SortSplit()
Dim wks As Worksheet
Dim iRow As Integer, iRowT As Integer
Application.ScreenUpdating = False
Set wks = ActiveSheet
Range("A1").Sort key1:=Range("A2"), order1:=xlAscending, header:=xlYes
iRow = 2
Do Until IsEmpty(wks.Cells(iRow, 1))
If Left(wks.Cells(iRow, 1), 1) <> Left(wks.Cells(iRow - 1, 1), 1) Then
Worksheets.Add after:=Worksheets(Worksheets.Count)
Rows(1).Value = wks.Rows(1).Value
Rows(1).Font.Bold = True
Columns(1).Font.Bold = True
ActiveSheet.Name = Left(wks.Cells(iRow, 1), 1)
iRowT = 1
End If
iRowT = iRowT + 1
Rows(iRowT).Value = wks.Rows(iRow).Value
iRow = iRow + 1
Loop
Worksheets(1).Select
Application.ScreenUpdating = True
End Sub
This code will sort the active sheet on Column A assuming that row 1 are headers. You would need to adjust the column for sorting as well as for the data to be compared (itīs Column A here). If you have rows that go beyond 32.767 you would need to replace the data type Integer with Long to avoid a run-time error.
If you have questions please donīt be afraid to ask.
Ciao,
Holger
Bookmarks