Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Return to active cell after sort

Is it possible to edit the Sort Routine so that when the sort is completed,
the Range("B6:G1000") will be deselected and the active cell will be the
cell that was active when the Sort Routine started?



Sub SortNames()
'
' Macro1 Macro
'

'
Application.ScreenUpdating = False

ActiveWindow.SmallScroll Down:=-6
Range("B6:G1000").Select
ActiveWorkbook.Worksheets("Jan 08").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Jan 08").Sort.SortFields.Add
Key:=Range("B6:B1000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Jan 08").Sort
.SetRange Range("B6:G1000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Application.ScreenUpdating = True

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Return to active cell after sort

I think it's your .select statement that's causing the problem:

Option Explicit
Sub SortNames()
Application.ScreenUpdating = False

with ActiveWorkbook.Worksheets("Jan 08")
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range("B6:B1000"), _
SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
with .Sort
.SetRange .parent.Range("B6:G1000")
.Header = xlGuess 'why let excel guess if you have headers????
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
end with
End With

Application.ScreenUpdating = True

End Sub

Untested, uncompiled.

(Is this for xl2007?)

"Patrick C. Simonds" wrote:

Is it possible to edit the Sort Routine so that when the sort is completed,
the Range("B6:G1000") will be deselected and the active cell will be the
cell that was active when the Sort Routine started?

Sub SortNames()
'
' Macro1 Macro
'

'
Application.ScreenUpdating = False

ActiveWindow.SmallScroll Down:=-6
Range("B6:G1000").Select
ActiveWorkbook.Worksheets("Jan 08").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Jan 08").Sort.SortFields.Add
Key:=Range("B6:B1000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Jan 08").Sort
.SetRange Range("B6:G1000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Application.ScreenUpdating = True

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Return to active cell after sort

Thank you sir

It worked wonderfully




"Dave Peterson" wrote in message
...
I think it's your .select statement that's causing the problem:

Option Explicit
Sub SortNames()
Application.ScreenUpdating = False

with ActiveWorkbook.Worksheets("Jan 08")
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=.Range("B6:B1000"), _
SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
with .Sort
.SetRange .parent.Range("B6:G1000")
.Header = xlGuess 'why let excel guess if you have headers????
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
end with
End With

Application.ScreenUpdating = True

End Sub

Untested, uncompiled.

(Is this for xl2007?)

"Patrick C. Simonds" wrote:

Is it possible to edit the Sort Routine so that when the sort is
completed,
the Range("B6:G1000") will be deselected and the active cell will be
the
cell that was active when the Sort Routine started?

Sub SortNames()
'
' Macro1 Macro
'

'
Application.ScreenUpdating = False

ActiveWindow.SmallScroll Down:=-6
Range("B6:G1000").Select
ActiveWorkbook.Worksheets("Jan 08").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Jan 08").Sort.SortFields.Add
Key:=Range("B6:B1000" _
), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Jan 08").Sort
.SetRange Range("B6:G1000")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Application.ScreenUpdating = True

End Sub


--

Dave Peterson


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make active cell a variable, return there later Andyjim Excel Programming 3 January 5th 08 04:30 PM
Return to active cell Alex.W Excel Discussion (Misc queries) 2 June 19th 07 11:35 PM
Return to active cell after macro completes Dave Excel Programming 3 August 29th 06 03:06 AM
I need to sort an active sheet using the col of the active cell HamFlyer Excel Programming 3 June 6th 06 07:25 PM
In macros, an instruction that will return the position of the Active Cell aca[_4_] Excel Programming 2 January 20th 06 10:50 PM


All times are GMT +1. The time now is 04:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"