Sort of range leaves range "selected"

M

Mike Jamesson

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
 
X

XP

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.
 
S

Susan

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
 
M

Mike Jamesson

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
 

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