Anne Troy

MrExcel MVP
Joined
Feb 18, 2002
Messages
2,632
Office Version
  1. 365
Platform
  1. Windows
No clue why this works on my machine, but throws a 438 on another user's machine. Anybody? This is all my code. It's my boss, so I didn't exactly want to get him involved in debugging. Let me know if I MUST. I figure it's something I can't pick out because I steal code, I don't really write much. :)

Code:
Sub LNSort()

'
LastRow = Range("A" & Rows.Count).End(xlUp).Row
'
    Columns("A:AH").Select
    ActiveWorkbook.Worksheets("ALL").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("ALL").Sort.SortFields.Add2 Key:=Range("E2:E" & LastRow), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("ALL").Sort.SortFields.Add2 Key:=Range("F2:F" & LastRow), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("ALL").Sort
        .SetRange Range("A1:AH" & LastRow)
        .Header = xlYes
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A2").Select
End Sub

Sub GetATL()
'Get Atlas Drivers Only
If ActiveSheet.AutoFilterMode Then ActiveSheet.Cells.AutoFilter
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData

Call LNSort

    Selection.AutoFilter
    ActiveSheet.Range("$A:$A").AutoFilter Field:=2, Criteria1:="ATL"
    Range("A2").Select
End Sub



Sub GetMST()
'Get Med-Spec Drivers Only
If ActiveSheet.AutoFilterMode Then ActiveSheet.Cells.AutoFilter
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData


Call LNSort
    Selection.AutoFilter
    ActiveSheet.Range("$A:$A").AutoFilter Field:=2, Criteria1:="MST"
    Range("A2").Select
End Sub

Sub GetLTM()
'Get Logistics Drivers Only
If ActiveSheet.AutoFilterMode Then ActiveSheet.Cells.AutoFilter
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData


Call LNSort
Selection.AutoFilter
    ActiveSheet.Range("$A:$A").AutoFilter Field:=2, Criteria1:="LTM"
    Range("A2").Select
End Sub

Sub GetALL()
'Clear filters
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
Range("A2").Select
'
'    ActiveSheet.ShowAllData
'    Range("A2").Select
End Sub

Sub GetECTM()
'Get All Drivers Only
If ActiveSheet.AutoFilterMode Then ActiveSheet.Cells.AutoFilter
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData

Call LNSort
Selection.AutoFilter
    ActiveSheet.Range("$A:$A").AutoFilter Field:=1, Criteria1:="ECT"
    Range("A2").Select
End Sub

Sub GetPXTM()
'Get Med-Spec Drivers Only
If ActiveSheet.AutoFilterMode Then ActiveSheet.Cells.AutoFilter
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData

    LastRowE = Range("E" & Rows.Count).End(xlUp).Row
    LastRowA = Range("A" & Rows.Count).End(xlUp).Row

Call LNSort
Selection.AutoFilter
    ActiveSheet.Range("$A:$A").AutoFilter Field:=1, Criteria1:="PXT"
    Range("A2").Select
End Sub

Sub GetMWTM()
'Get Logistics Drivers Only
If ActiveSheet.AutoFilterMode Then ActiveSheet.Cells.AutoFilter
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData


Call LNSort
Selection.AutoFilter
    ActiveSheet.Range("$A:$A").AutoFilter Field:=1, Criteria1:="MWT"
    Range("A2").Select
End Sub

Sub GetWCTM()
'Get Logistics Drivers Only
If ActiveSheet.AutoFilterMode Then ActiveSheet.Cells.AutoFilter
If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData


Call LNSort
Selection.AutoFilter
    ActiveSheet.Range("$A:$A").AutoFilter Field:=1, Criteria1:="WCT"
    Range("A2").Select
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
It would be good to know what line of code throws up that error though
 
Upvote 0
Are you both using the same version of Excel.
I believe that Add2 is only available with the 365 version of 2016
 
Upvote 0
Yep - changing it to Add should work for any version with the Sort object.
 
Upvote 0
You forgot to mention the name of the sheet in these 3 lines (I think):
Rich (BB code):
LastRow = Sheets("ALL").Range("A" & Sheets("ALL").Rows.Count).End(xlUp).Row
'
    Sheets("ALL").Columns("A:AH").Select   ' Remove this line.
'
'
'
Sheets("ALL").Range("A2").Select
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

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