mrMozambique
Board Regular
- Joined
- Mar 9, 2005
- Messages
- 97
Greetings, all. When I run the following macro from anywhere in my workbook, it works fine. However, when I call it on the Terminate Even of a userform, it gives me an "object-required" 424 error. I have a suspicion it's because it doesn't know how to grab the "sites" worksheet while it's closing the userform, but I'm not sure. Can anyone give me some guidance?
Code:
Sub sortsites2()
'
' sortsites2 Macro
'
'
Sheets("sites").Select
Range("E1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.Worksheets("sites").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("sites").Sort.SortFields.Add Key:=Range("E2:E2627") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("sites").Sort.SortFields.Add Key:=Range("F2:F2627") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("sites").Sort.SortFields.Add Key:=Range("H2:H2627") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("sites").Sort
.SetRange Range("E1:R2627")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Facilities").Select
End Sub