I need to have a macro that will sort the entire Excel worksheet then insert a page break when the value in lets say column C changes (the next time I use the macro the column could be H. The macro below was given to me from someone in this forum, but it only sorts one column, not the entire worksheet. Would anyone know how to modify this macro or have one that does what I need? All help is greatly appreciated!
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Sub Sort_InsertPageBreaks()
Dim rng As Range, cell As Range
Set rng = Range([B2], [B9999].End(xlUp))
rng.Sort Key1:=rng(1, 1)
For Each cell In rng
If cell.Value <> cell(2, 1).Value Then
cell(2, 1).EntireRow.PageBreak = xlManual
End If
Next
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Sub Sort_InsertPageBreaks()
Dim rng As Range, cell As Range
Set rng = Range([B2], [B9999].End(xlUp))
rng.Sort Key1:=rng(1, 1)
For Each cell In rng
If cell.Value <> cell(2, 1).Value Then
cell(2, 1).EntireRow.PageBreak = xlManual
End If
Next
End Sub