Need a macro to run sort automatically

B

Bob Phillips

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top