Need a macro to run sort automatically

  • Thread starter Thread starter gmangad
  • Start date Start date
Here's a simple macro.

Sub SortRows()
Dim cLastRow As Long
Dim rng As Range

With ActiveCell
cLastRow = Cells(Rows.Count, .Column).End(xlUp).Row
Set rng = Range(.Offset(1, 0), Cells(cLastRow, .Offset(0,
1).Column))
rng.Sort key1:=.Offset(2, 0), header:=xlYes
End With

End Sub

Select the cell that says DEPARTMENT-n, and it will sort the block below,

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top