Sub SortYear()
Dim xlSort As XlSortOrder
Dim ws As Worksheet
Dim rngEnd As Range
For Each ws In Worksheets(Array("Sheet1", "Sheet2", "Sheet3"))
With ws
Set rngEnd = Nothing
Set rngEnd = .Range("A:A").Find("End", , xlFormulas, xlPart, xlByRows, xlNext, False)
If rngEnd Is Nothing Then
MsgBox "Can't find 'End' on " & .Name & ".", , "No Match Found"
Else
.Unprotect msPASSWORD
If (StrComp(UCase(.Range("A10").Value), UCase(.Range("A11").Value)) > 0) Then
xlSort = xlAscending
Else
xlSort = xlDescending
End If
With .Range("A10", rngEnd.Offset(-2)).EntireRow
.Sort Key1:=.Range("A10"), Order1:=xlSort, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With
.Protect Password:=msPASSWORD, DrawingObjects:=False, Contents:=True, Scenarios:=True
End If
End With
Next ws
ActiveSheet.EnableSelection = xlNoRestrictions
Sheets("SheetA").Activate
End Sub
Bookmarks