Help with Macro

Noxqss38242

Board Regular
Joined
Sep 15, 2017
Messages
223
Office Version
  1. 2016
Currently the macro, when button is selected, will arrange data in largest to smallest.
I want it to actually arrange smallest to largest.

Here are the macros that may be the culprit:

Sub srtdeviation()
'
' srtdeviation Macro
'

'
ActiveWorkbook.Worksheets("VMRSMAIL").ListObjects("Table1").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("VMRSMAIL").ListObjects("Table1").Sort.SortFields. _
Add2 Key:=Range("Table1[[#All],[SRT DEVIATION]]"), SortOn:=xlSortOnValues, _
Order:=xlAcending, DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("VMRSMAIL").ListObjects("Table1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub


AND.....

Sub SortSRTDev()
'
' SortSRTDev Macro
'

'
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=24, Criteria1:= _
">-50", Operator:=xlAnd
End Sub



What's the fix?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You've got a typo Order:=xlAcending is missing an s
 
Upvote 0
Hahaha....yeah, I hurried and changed it back... It said Ascending at first so I changed it to Descending but that didn't change anything. What am I missing?
 
Upvote 0
That should sort ascending, what sort of values do you have in that column?
 
Upvote 0
Daily Tech Report.xlsm
ABCDEFGHIJKLMNOPQRSTUVWX
11RO #TERMDATEUNITTRLRREASSYSTASSYCOMPWORKPOSFAILTECHSTART DATESTART TIMEEND DATEEND TIMETECH HRSTASK HRSLABOR $PARTS $VMRS LINESRTSRT DEVIATION
17S0INSHOP IN 4/6/2021INSHOP MAINT INDRCTCLEAN CLEAN ASSESS99DIRTY PV1 4/06/21 5:33 4/06/21 5:430.216.7918.50CLEAN SHOP 016.7
18S0INSHOP IN 4/6/2021INSHOP MAINT INDRCTCLEAN CLEAN ASSESS99DIRTY PV1 4/06/21 13:36 4/06/21 13:550.316.7918.50CLEAN SHOP 016.7
19S0INSHOP IN 4/6/2021INSHOP MAINT INDRCTCLEAN CLEAN ASSESS99DIRTY PV1 4/06/21 14:17 4/07/21 5:191516.7918.50CLEAN SHOP 016.7
20S0INSHOP IN 4/6/2021INSHOP MAINT INDRCTCLEAN CLEAN ASSESS99DIRTY PV1 4/07/21 5:19 4/07/21 6:030.716.7918.50CLEAN SHOP 016.7
21S0INSHOP IN 4/6/2021INSHOP MAINT INDRCTCLEAN CLEAN ASSESS99DIRTY JJ1 4/07/21 5:12 4/07/21 5:420.516.7918.50CLEAN SHOP 016.7
42B1169615 WM 3/3/202116931 ACCID CAB HOOD ASMBLYRPLUSE99ACCID JH1 3/03/21 12:58 3/03/21 15:58311.26161519.34ACC: HOOD DAMAGE ON P/S REMOVE HOOD 5.65.60
43B1169615 WM 3/3/202116931 ACCID CAB HOOD ASMBLYRPLUSE99ACCID GS1 3/12/21 11:14 3/12/21 11:280.211.26161519.34ACC: HOOD DAMAGE ON P/S REMOVE HOOD 5.65.60
44B1169615 WM 3/3/202116931 ACCID CAB HOOD ASMBLYRPLUSE99ACCID EHS 3/12/21 11:14 3/12/21 11:280.211.26161519.34ACC: HOOD DAMAGE ON P/S REMOVE HOOD 5.65.60
45B1169615 WM 3/3/202116931 ACCID CAB HOOD ASMBLYRPLUSE99ACCID GS1 3/12/21 12:01 3/12/21 15:573.911.26161519.34ACC: HOOD DAMAGE ON P/S REMOVE HOOD 5.65.60
46B1169615 WM 3/3/202116931 ACCID CAB HOOD ASMBLYRPLUSE99ACCID EHS 3/12/21 12:01 3/12/21 15:573.911.26161519.34ACC: HOOD DAMAGE ON P/S REMOVE HOOD 5.65.60
47B1178396 IN 3/5/202120431 MAINT FUELSYDEF LINE RPLNEW99BROKEN JJ1 3/05/21 12:00 3/05/21 13:511.910.9599.5144.18COOLANT LINES TO DEF TANK BROKEN 5.35.60
48B1178396 IN 3/5/202120431 MAINT FUELSYDEF LINE RPLNEW99BROKEN JJ1 3/05/21 14:10 3/05/21 15:060.910.9599.5144.18COOLANT LINES TO DEF TANK BROKEN 5.35.60
49B1178396 IN 3/5/202120431 MAINT FUELSYDEF LINE RPLNEW99BROKEN JJ1 3/08/21 5:30 3/08/21 7:412.210.9599.5144.18COOLANT LINES TO DEF TANK BROKEN 5.35.60
50B1178396 IN 3/5/202120431 MAINT FUELSYDEF LINE RPLNEW99BROKEN JJ1 3/08/21 8:00 3/08/21 10:00210.9599.5144.18COOLANT LINES TO DEF TANK BROKEN 5.35.60
51B1178396 IN 3/5/202120431 MAINT FUELSYDEF LINE RPLNEW99BROKEN JJ1 3/09/21 6:00 3/09/21 7:401.710.9599.5144.18COOLANT LINES TO DEF TANK BROKEN 5.35.60
52B1178396 IN 3/5/202120431 MAINT FUELSYDEF LINE RPLNEW99BROKEN JJ1 3/09/21 8:00 3/09/21 10:092.210.9599.5144.18COOLANT LINES TO DEF TANK BROKEN 5.35.60
64S1174578 MU 3/25/202116988 ACCID FUELSYFUETNKTANK RPLNEW22CRUSHD DCF 3/25/21 12:05 3/25/21 14:102.110.25611595.56FUEL TANK SMASHED 9.60.60
65S1174578 MU 3/25/202116988 ACCID FUELSYFUETNKTANK RPLNEW22CRUSHD DJM 3/25/21 12:12 3/25/21 14:09210.25611595.56FUEL TANK SMASHED 9.60.60
66S1174578 MU 3/25/202116988 ACCID FUELSYFUETNKTANK RPLNEW22CRUSHD DCF 3/25/21 14:31 3/25/21 15:471.310.25611595.56FUEL TANK SMASHED 9.60.60
67S1174578 MU 3/25/202116988 ACCID FUELSYFUETNKTANK RPLNEW22CRUSHD DJM 3/25/21 14:31 3/25/21 17:042.610.25611595.56FUEL TANK SMASHED 9.60.60
68S1174578 MU 3/25/202116988 ACCID FUELSYFUETNKTANK RPLNEW22CRUSHD DJM 3/25/21 17:37 3/25/21 18:581.410.25611595.56FUEL TANK SMASHED 9.60.60
69S1174578 MU 3/25/202116988 ACCID FUELSYFUETNKTANK RPLNEW22CRUSHD DJM 3/25/21 20:37 3/25/21 21:250.810.25611595.56FUEL TANK SMASHED 9.60.60
75B1170951 MU 3/4/2021 633853MAINT TLREARDOOR BLANK RPLNEW22BROKEN WG1 3/12/21 10:04 3/12/21 14:114.19.8539451.47LEFT DOOR RUSTED THRU ** WAITING PARTS ON PAD 5** 54.80
76B1170951 MU 3/4/2021 633853MAINT TLREARDOOR BLANK RPLNEW22BROKEN TRB 3/12/21 11:51 3/12/21 14:112.39.8539451.47LEFT DOOR RUSTED THRU ** WAITING PARTS ON PAD 5** 54.80
VMRSMAIL
Cell Formulas
RangeFormula
X75:X76,X64:X69,X42:X52,X17:X21X17=[@[TASK HRS]]-[@SRT]



I click on the button for "Sort SRT Dev" and to me it just doesn't work right. You figure it would be ascending no matter what but as you can see, it goes from 16.7 to 5.6 to 0.6 to 4.8?
Something is surely off...and I want it to go from least amount of deviation to most...so it would be 0.6 at the top and 16.7 at the bottom.
 
Upvote 0
With that data your macro works for me, once the typo is corrected.
Is that the actual formula you have in that column? Also are there formulae in any other columns?
 
Upvote 0
Hmm...you may be on to something. After manually sorting smallest to largest, it works. I can click filters off, click on almost everything and it still works. All other buttons that are assigned macros work. Except "SORT Task Time". When I click on that one, it throws everything else off and the sort feature no longer works. Even if I clear all filters, the sorting for SRT deviation won't work.

Here is the macro for "SORT Task Time":

Sub tasktime()
'
' tasktime Macro
'

'
ActiveWorkbook.Worksheets("VMRSMAIL").ListObjects("Table1").Sort.SortFields. _
Clear
ActiveWorkbook.Worksheets("VMRSMAIL").ListObjects("Table1").Sort.SortFields. _
Add2 Key:=Range("Table1[[#All],[TASK HRS]]"), SortOn:=xlSortOnValues, _
Order:=xlDescending, DataOption:=xlSortTextAsNumbers
With ActiveWorkbook.Worksheets("VMRSMAIL").ListObjects("Table1").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
 
Upvote 0
Okay, so I noticed that a little arrow is applied to SRT Deviation when "sorted". However, I'm guessing all other buttons were working because I manually sorted it and the data remained sorted in that way. When I click on Sort Task Time, the arrow from SRT Deviation is removed and placed on Sort Task Time....which it should do. However, the issue is when click back on SRT Deviation, it doesn't remove the sorting of the task time and doesn't apply it for SRT Deviation. Something is a foot!
 
Upvote 0
You code work for me, so not quite sure what is going on.
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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