Sorting Code (alphabetize) stopped working

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
655
This line of code used to work. Now this, among a few others, doesn't seem to work. It kicks up a 438 "Object doesn't support this property or method" code and highlights the top line.... ideas? I can sort if I manually highlight and click sort....

Code:
    Range("B3:K102").Select
    ActiveWorkbook.Worksheets("Ports").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Ports").Sort.SortFields.Add2 Key:=Range("B3:B102") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Ports").Sort
        .SetRange Range("B3:K102")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
It kicks up a 438 "Object doesn't support this property or method" code and highlights the top line

Code:
Sub ThisLineIsGood()
   Range("B3:K102").Select
End Sub

The above line works without issue for me but what is happening in your code before that line ?
 
Last edited:
Upvote 0
Code:
Sub ThisLineIsGood()
   Range("B3:K102").Select
End Sub

The above line works without issue for me but what is happening in your code before that line ?


unfortunately nothing. I meant to post the full sub and missed it. Here ya go


Code:
Sub Alphabetize()

'Begins Error Handling Code
On Error GoTo Helper


Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
    Range("B3:K102").Select
    ActiveWorkbook.Worksheets("Ports").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Ports").Sort.SortFields.Add2 Key:=Range("B3:B102") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Ports").Sort
        .SetRange Range("B3:K102")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False


'Error Clearing Code
Exit Sub
Helper:
    resp = MsgBox("We're sorry to see you've encountered an error." & vbCrLf & vbCrLf & "To proceed, we recommend you contact the Developer " & _
    "with error codes [1129] and " & "[" & Err.Number & "-" & Err.Description & "]." & vbCrLf & vbCrLf & "To attempt to patch your problem at least " & _
    "temporarily, we recommend you click [Yes] to see help directions. Would you like to continue?", vbYesNoCancel, name)
        If resp = vbYes Then
            UserForm18.Show
            'MsgBox ("Success")
        ElseIf resp = vbNo Then
            Exit Sub
        ElseIf resp = vbCancel Then
            Exit Sub
        End If
        
End Sub
[/code]
 
Upvote 0
Range B3:K102 is referred to in the code but selected cells are not used so the line is of no consequence
Delete the line below
Code:
Range("B3:K102").Select

and run the code again to see if the code now stops further down
 
Last edited:
Upvote 0
Yep- kicked a 438 Object doesn't support this property or method
on this line of code

Code:
    ActiveWorkbook.Worksheets("Ports").Sort.SortFields.Add2 Key:=Range("B3:B102") _        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
 
Upvote 0
Code:
Sub SortDataWithoutHeader()
       Dim rng As Range
       Set rng = ActiveWorkbook.Worksheets("Ports").Range("B3:K102")
       rng.Sort Key1:=Range("B3"), Order1:=xlAscending, Header:=xlNo
End Sub

Also - spot your error!

Code:
Sub Alphabetize()
On Error GoTo Helper
Application.DisplayAlerts = [COLOR=#ff0000]False[/COLOR]
Application.ScreenUpdating = [COLOR=#ff0000]False[/COLOR]
Application.EnableEvents = [COLOR=#ff0000]False[/COLOR]
[I]
Sorting code here [/I]

Application.DisplayAlerts = False ??
Application.ScreenUpdating = False ?? 
Application.EnableEvents = False ??
 
Last edited:
Upvote 0
Ahhhh

Sloppy on my part. That's fixed. Thank you.


As for your code- it kicked an error again- 1004 Sort method of range class failed....

Not sure why these are kicking errors because my original code worked at one time....
 
Upvote 0
Is the worksheet protected :confused::confused:

If so ...
Code:
Sub SortDataWithoutHeader()
    Const pWord = "[COLOR=#ff0000][I]password[/I][/COLOR]"
    Dim rng As Range
    Set rng = ActiveWorkbook.Worksheets("Ports").Range("B3:K102")
    With rng
        .Parent.Unprotect pWord
        .Sort Key1:=Range("B3"), Order1:=xlAscending, Header:=xlNo
        .Parent.Protect pWord
    End With
End Sub
 
Last edited:
Upvote 0
Ahhh ha! Yes

So that's very interesting. Yes, the sheet was password protected. However, the fields being sorts were not part of the protection so I figured they should not have a problem....obviously not the case.

Thank you!

Now I get to ask why my buttons aren't working correctly on another routine!
 
Upvote 0
Glad that helped :beerchug:

Now I get to ask why my buttons aren't working correctly on another routine!
You do - but on another thread please
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top