Run sort macro on active worksheet

O

ordnance1

How can I make the code below work on any worksheet?

Sub SortByDate()

ActiveWorkbook.Worksheets("DateCheck").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("DateCheck").Sort.SortFields..Add Key:=Range( _
"C4:C24"), SortOn"=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("DateCheck").Sort
.SetRange Range( "B3:K24" )
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 

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

Similar Threads

Applying Variables to SORT 4
Undo Macro Action 3
Modify Sort Routine to inlcude All Data 2
Clear Check Box 2
VBA 2 Codes 2
Sort Macro Compatibility 3
writing a sort macro 2
Sorting Question 5

Top