Sort variable range in descending order

J

J.W. Aldridge

Code below works fine but need range to be variable. May not be R61c4
(row 61). Need to sort on whatever row lands.


Sub Up_N_Fix()

'
Range("D65536").Select
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Sort Key1:="R61C4", Order1:=xlDescending,
Type:=xlSortValues, _
OrderCustom:=1, Orientation:=xlLeftToRight

End Sub


Thanx
 
M

meh2030

Code below works fine but need range to be variable. May not be R61c4
(row 61). Need to sort on whatever row lands.

Sub Up_N_Fix()

'
    Range("D65536").Select
    Selection.End(xlUp).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Sort Key1:="R61C4", Order1:=xlDescending,
Type:=xlSortValues, _
        OrderCustom:=1, Orientation:=xlLeftToRight

End Sub

Thanx

J.W. Aldridge,

I think this is what you are looking to do. I did the generic sort
parameters, so you can change those to what you want.

Best,

Matt Herbert

Sub Up_N_Fix()

Dim rngSort As Range
Dim lngStartRow As Long
Dim lngEndCol As Long
Dim rngSortCell As Range

Set rngSort = Range("D65536").End(xlUp).CurrentRegion

lngStartRow = rngSort.Cells(1).Row
lngEndCol = rngSort.Cells(rngSort.Cells.Count).Column

Set rngSortCell = Cells(lngStartRow, lngEndCol)

rngSort.Sort Key1:=rngSortCell, Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal
End Sub
 
J

J.W. Aldridge

Thanx, I believe this would work however I am getting all sorts of
compile errors. trying to fix the arrangements but to no luck thus
far.
 
M

meh2030

Thanx, I believe this would work however I am getting all sorts of
compile errors. trying to fix the arrangements but to no luck thus
far.

J.W.,

The code won't simply work if you copy and paste it from groups.google
into your code module. If you simply copy and paste, you will get a
lot of red text in your code module. This is because your line
continuation characters, i.e. "_" need to be at the end of a line.
Another option is to delete all spacing such that the line starting
"rngSort.Sort..." is on one line.

Matt Herbert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top