ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sort of range leaves range "selected" (https://www.excelbanter.com/excel-programming/414629-sort-range-leaves-range-selected.html)

Mike Jamesson

Sort of range leaves range "selected"
 
I have a dozen or so worksheets with the same template, and my code does a
sort on a range within each sheet. After the sort, tho, the range is still
"highlighted", as if I had selected the range (which I didn't, not with
"select", at least), i.e., it's shaded just as if I had clicked on the upper
left cell of the range and dragged down to the lower right. I would like the
range to remain visually unaltered, but I can't figure out how.

Thanks in advance

Mike J

XP

Sort of range leaves range "selected"
 
Not sure if this would help, but you could just add one line at the end of
your sort code to select one cell of your choice, for example:

[A2].Select

Hope this helps.

"Mike Jamesson" wrote:

I have a dozen or so worksheets with the same template, and my code does a
sort on a range within each sheet. After the sort, tho, the range is still
"highlighted", as if I had selected the range (which I didn't, not with
"select", at least), i.e., it's shaded just as if I had clicked on the upper
left cell of the range and dragged down to the lower right. I would like the
range to remain visually unaltered, but I can't figure out how.

Thanks in advance

Mike J


Susan

Sort of range leaves range "selected"
 
mike - using this sub on excel 2000, my ranges don't get
highlighted.........

For Each ws In wb.Worksheets
ws.Activate
myLastRow = ws.Cells(10000, 1).End(xlUp).Row
Set myRange = ws.Range("a1:b" & myLastRow)
myRange.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo,
_
OrderCustom:=1, Orientation:=xlTopToBottom
Next ws

don't know why your ranges are highlighted.
susan



On Jul 25, 12:23*pm, Mike Jamesson
wrote:
I have a dozen or so worksheets with the same template, and my code does a
sort on a range within each sheet. *After the sort, tho, the range is still
"highlighted", as if I had selected the range (which I didn't, not with
"select", at least), i.e., it's shaded just as if I had clicked on the upper
left cell of the range and dragged down to the lower right. *I would like the
range to remain visually unaltered, but I can't figure out how.

Thanks in advance

Mike J



Mike Jamesson

Sort of range leaves range "selected"
 
Thanks for the response, here's my code:

Sub SortTallies(targSheet As Worksheet)
Dim targRange As Range
' Application.ScreenUpdating = False 'doesn't help
Set targRange = targSheet.Range("TargDates")
Set targRange = Range(targRange, targRange.End(xlDown))
Set targRange = Range(targRange, targRange.End(xlToRight))
targSheet.Sort.SortFields.Clear
targSheet.Sort.SortFields.Add Key:=targRange.Range( _
"A1:A8"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With targSheet.Sort
.SetRange targRange
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
.SortFields.Clear 'didn't work to clear visible "selection" effects
End With
' Set targRange = targSheet.Range("A1") 'didn't work to clear visible
"selection" effects
' targRange.Select 'bombed
' Application.ScreenUpdating = True
End Sub

As you can see, I used a recorded macro as my basis; also, I don't want to
select either the sheets or the ranges, and have successfully avoided doing
so. But then when I go to the sheets, the area that got sorted is "selected"
visually, and each sheet shows this phenomenon. I'm using Excel 2007 SP1,
btw.

Thanks again

Mike

"Susan" wrote:

mike - using this sub on excel 2000, my ranges don't get
highlighted.........

For Each ws In wb.Worksheets
ws.Activate
myLastRow = ws.Cells(10000, 1).End(xlUp).Row
Set myRange = ws.Range("a1:b" & myLastRow)
myRange.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo,
_
OrderCustom:=1, Orientation:=xlTopToBottom
Next ws

don't know why your ranges are highlighted.
susan



On Jul 25, 12:23 pm, Mike Jamesson
wrote:
I have a dozen or so worksheets with the same template, and my code does a
sort on a range within each sheet. After the sort, tho, the range is still
"highlighted", as if I had selected the range (which I didn't, not with
"select", at least), i.e., it's shaded just as if I had clicked on the upper
left cell of the range and dragged down to the lower right. I would like the
range to remain visually unaltered, but I can't figure out how.

Thanks in advance

Mike J





All times are GMT +1. The time now is 11:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com