View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter Rooney Peter Rooney is offline
external usenet poster
 
Posts: 325
Default Sort without Selecting

Hi, Jody,

Thjere are lots of ways you can sort more efficiently, without selecting
forst:

Sub Macro5()
Range("B11:T17").Sort Key1:=Range("B12"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

I find it easier to give range names to header cells in your database, so,
id you insert or delete rows, your code always points to the same cell.

In the above example, you could replays Range("B12") with
Range("SalesColHeader") for example, where SalesColHeader is a name applied
to cell B12.

I always call the first field header "DatabaseStart", thus the above example
would begin:
Range("DatabaseStart").Sort Key1

Hope this is of some use

Happy Christmas

Pete



"ssjody" wrote:

My current code for Sorting selects the sheet, sorts the data then
returns back to my Data Entry sheet. How can I have this perform this
without the code selecting the sheet? I just want it to happen in the
background without the sheets flashing back and forth while this
happens.

I did a search and found some suggestions but can't find one that works
for my application.

Thanks Jody

' SortcpModels
Sheets("cpModels").Select
Columns("A:B").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Sheets("Data Entry").Select
Range("B3").Select