sorting data

J

Jock

In a worksheet which will be added to weekly, I would like to sort the data
in columns A:AX by column D.
Rather than create a macro which will look at absolute references (ie.
A4:AX5000), can code be used to determine where the last row is and sort only
rows which contain data?
 
B

Barb Reinhardt

Try recording what you want to do with the data you have. Then, determine a
column that will have data in the last row

Dim lRow as long
Dim aWS as Excel.WOrksheet

set aWS = ActiveWorksheet

'Gets last row of data in column 1. Modify as needed

lRow = aWS.Cells(aws.rows.count,1).end(xlup).row

If you can't figure out how to concatenate that data with lRow, come back.

HTH,
Barb Reinhardt
 
P

Patrick Molloy

Assume D is all data then

with range(range("A1"),Range("D1").End(xlDown) )
.Sort range("d1")
end with
 
G

GerryGerry

Try the following:-

Private sub sort()
range("A4:AX4",range("A4:AX4").end(xlDown)).sort range("D4"), xlAscending
End sub
 
Top