Fast Way to Sort Rows Using VBA

mBlack

New Member
Joined
Oct 21, 2005
Messages
4
Can anyone share a fast way to sort rows (ascending or descending) in each section of a worksheet based on the value of a specified column using VBA?

I have working code but there are many lines and seems very cumbersome. I know there is a quicker way to do it that I am not aware of.

Inserted is a workbook with an example of what I am trying to accomplish. I need to sort the rows in each section by Flight/Truck number or by the ETA/ETD.
Original FlytsTest.xls
ABCDEF
1OUTBOUNDFLIGHTS
2Flyt#CodeETDATD(+/-)DelayCode
31603SLC07550758-3
41606MIA084108401
51609AUS100410040
61610MCO10051022-17xld
71611FAT10181019-1
81612MSY1020100515
91625PVD10321040-8mech
10
11INBOUNDFLIGHTS
12Flyt#CodeETAATA(+/-)DelayCode
131754DAL15451546-1
141757PHX1550 
151758BFI16031624-21xld
161769DEN1557 
171776SFO1620 
188281EMA09300932-2
19
20OUTBOUNDTRUCKS
21Trk#CodeETDATD(+/-)DelayCode
2215648EBR1600 
2315739RDU1600 
2416057LIT1600 
2516330UUH1400 
2616331PPH1400 
2716516CLU1600 
2816521CMH1515 
29 
30
Arrival & Departure


Any help would greatly be appreciated!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Also I need to add that each section can have additional flights or truck routes added or taken away. I guess this is where I am getting hung up on the sorting because the ranges to sort are dynamic.
 
Upvote 0
Can you post your current code?
 
Upvote 0
Here is the current code I am using to sort ETA/ETD:

Sub SortByETA()

Dim cell As Variant

'ActiveSheet.Unprotect Password:="xxxx"
Application.ScreenUpdating = False

' OB Flyts
Worksheets("Arrival & Departure").Range("G5").Sort _
Key1:=Worksheets("Arrival & Departure").Columns("I"), _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

' IB Flyts
Worksheets("Arrival & Departure").Range("G19").Sort _
Key1:=Worksheets("Arrival & Departure").Columns("I"), _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

' OB Trks
Worksheets("Arrival & Departure").Range("G33").Sort _
Key1:=Worksheets("Arrival & Departure").Columns("I"), _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

' IB Trks
Worksheets("Arrival & Departure").Range("G47").Sort _
Key1:=Worksheets("Arrival & Departure").Columns("I"), _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Application.ScreenUpdating = True
'ActiveSheet.Protect Password:="xxxx"

End Sub


* Note the cells and columns are different in this code than the example sheet that I posted earlier.
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,673
Members
449,116
Latest member
HypnoFant

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