Re: Sort of range leaves range "selected" by MikeJamesson
MikeJamesson
Fri Jul 25 12:46:52 CDT 2008
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
> <MikeJames...@discussions.microsoft.com> 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
>
>