Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a range of values

Status
Not open for further replies.

t16turbo

Programmer
Mar 22, 2005
315
GB
hi there, I have a macro that selects a range of values that I then need to sort descending by column C.

the recorded macro has a distinct cell reference of C, rather than a value derived automatically

Code:
Range(Columns("B:B").Find("Unplanned").Offset(0, 1), _
    Columns("B:B").Find("Unplanned Total").Offset(0, 14)).Select
 Application.CutCopyMode = False





Selection.Sort Key1:=Range("C53"), Order1:=xlDescending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom


can anyone tell me if this would always work, or if there is a better way of doing it? (the range will not always be where it is.
column-wise it will be, but it may be several rows lower or several rows higher...



many thanks...
 
What does your data look like?

It sounds like you are sorting a chunk of data somewhere on the sheet, but that there are other chunks of data elsewhere on the sheet. Is that right?


[tt]_____
[blue]-John[/blue][/tt]

Help us help you. Please read FAQ181-2886 before posting.
 


Hi,

Code:
    With Range(Columns("B:B").Find("Unplanned").Offset(0, 1), _
        Columns("B:B").Find("Unplanned Total").Offset(0, 14))
    
        .Sort Key1:=.Cells(1, 1), Order1:=xlDescending, Header:=xlNo, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    End With


Skip,

[glasses] [red]Be Advised![/red]
A wee deranged psychic may be runnin' around out there!
SMALL MEDUIM @ LARGE[tongue]
 
thats right.

and I have tested by taking the chunk of data up several rows, and also changing the value of C53 (row 53 being the top row of the chunk of data originally) to C1 etc and it always sorts it by column C, regardless of the Row number...

its basically about 13 columns, with the first column containing the values that I need to sort by - text with preeeding numbers.
the rest of the columns are all numbers.

I just need to make sure that the macro, above will sort that range (selected by the Range statement) in the same way all the time.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top