I have this code that sorts my Used Range. It works, but there is a couple of annoying things I wish to correct.
1) How do you set the Page to sort without the Page being the active sheet? I discovered the sort was Erroring, and I couldn't figure out what was wrong. Apparently the sheet has to be active in order to do a sort. So as a quick fix I just activated the sheet then ran the code and then re-activate the other sheet.
2) Occasionally, I have a code that runs and moves one or two rows to another sheet which leaves Blank Rows. The Sort command strangely leaves the Blank Rows where they are, right in the middle of my Used Range. It just sorts around them. So I either need to figure out how to move the blank Rows down out of the Used Range, or just delete them.
Thanks for your help. Here's the code;
Code:Sub PrSort() Sheets("LD").Activate Dim srtCell As Range Sheets("LD").Range("J6:J62").ClearContents For Each srtCell In Sheets("LD").Range("J6:J62") If srtCell.Offset(0, -8) <> "" Then srtCell.Value = srtCell.Offset(0, -8).Value Else If srtCell.Offset(0, -7) <> "" Then srtCell.Value = srtCell.Offset(0, -7).Value End If End If Next Sheets("LD").Range("A6:J62").Sort Key1:=Range("J6"), Order1:=xlAscending, Header:=xlGuess, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End Sub




Reply With Quote
