I recorded this and ran it several times with no problem. Now when I try to run it I get error message "Runtime error 9" "Subscript out of range"
When I click "Debug", it highlights the line:
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
If I delete that line, the next time I try to run it I get error message something like "Can't run in break mode".
The full macro is:
Sub SortByCompanyName()
'
' SortByCompanyName Macro
'
'
Range("A4:O200").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A5:A122") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A4:O200")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A5").Select
End Sub
Any help would be greatly appreciated.
When I click "Debug", it highlights the line:
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
If I delete that line, the next time I try to run it I get error message something like "Can't run in break mode".
The full macro is:
Sub SortByCompanyName()
'
' SortByCompanyName Macro
'
'
Range("A4:O200").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A5:A122") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A4:O200")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A5").Select
End Sub
Any help would be greatly appreciated.