Data sort on dynamic range

Callum2010

New Member
Joined
Mar 29, 2012
Messages
3
Hi

I was after some assitance performing a data sort on a range that is dynamic as opposed to fixed. However the range A21:AA755 will grow over time.

Does anyone have any idea?

Currently i have the following code

Sub Sort()
' Sort Macro
Application.ScreenUpdating = False
Sheet1.Unprotect Password:="maso1975"
Range("A21:AA755").Sort Key1:=Range("S22"), Order1:=xlAscending, Key2:= _
Range("Q22"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=6, _
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, Key3:=Range("N22"), Order1:=xlAscending
Sheet1.Protect Password:="maso1975", AllowFiltering:=True, DrawingObjects:=False
Application.Goto Reference:=Range("Q22"), Scroll:=True
ActiveSheet.Range("S21").Select
Application.ScreenUpdating = True
End Sub
 

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.
Try

Code:
Sub aSort()
' Sort Macro
Dim LR As Long
Application.ScreenUpdating = False
Sheet1.Unprotect Password:="maso1975"
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A21:AA" & LR).Sort Key1:=Range("S22"), Order1:=xlAscending, Key2:= _
Range("Q22"), Order2:=xlAscending, Header:=xlGuess, OrderCustom:=6, _
MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, Key3:=Range("N22"), Order1:=xlAscending
Sheet1.Protect Password:="maso1975", AllowFiltering:=True, DrawingObjects:=False
Application.Goto Reference:=Range("Q22"), Scroll:=True
ActiveSheet.Range("S21").Select
Application.ScreenUpdating = True
End Sub

You should avoid using VBA keywords like Sort as the names of macros.
 
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,696
Members
449,464
Latest member
againofsoul

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