Sort and Autofill Range

marka87uk

Board Regular
Joined
Mar 24, 2007
Messages
247
Hi,

I've recorded a macro to sort some data I have to do on a regular basis. The problem is the number of rows can change but the macro recorded references to the range I've recorded.

e.g.
Range("A1:S2429").Sort
Selection.AutoFill Destination:=Range("C2:C1249")

I can I make it sort all of the data, and likewise, autofill to the bottom row?

Thanks!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try like this

Code:
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("A1:S" & LR).Sort
Selection.AutoFill Destination:=Range("C2:C" & LR)
 
Upvote 0
You can detect the last row in a column and hold it in a variable like this:

Code:
Dim lngLastRow As Long
lngLastRow = Range("A" & Rows.Count).End(xlUp).Row

Range("A1:S" & lngLastRow).Sort
Selection.AutoFill Destination:=Range("C2:C" & lngLastRow)

Dom
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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