View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Sorting data in Excel

I don't like using the select method. Look at the code below. I used cell
to select the entire worksheet for the sort range. I'm not sure which
worksheet you want to sort so I have both sets of code below

Private Sub Workbook_Open()
with Sheets("ScoutList08 & Sales-to-date")
.Range("B2:B75").Copy _
destination:=Sheets("DataEntry").Range("C5000").Se lect
.cells.Sort _
Key1:=Range("C5001"), _
Order1:=xlAscending, _
Header:=xlGuess
end with
End Sub


Private Sub Workbook_Open()
with Sheets("ScoutList08 & Sales-to-date")
.Range("B2:B75").Copy _
destination:=Sheets("DataEntry").Range("C5000").Se lect
Sheets("DataEntry").cells.Sort _
Key1:=Range("C5001"), _
Order1:=xlAscending, _
Header:=xlGuess
end with
End Sub

"Cartoper" wrote:

I am a C/C++/.Net developer. I am working on a basic Excel
spreadsheet for my son's Boy Scout Troop. A friend gave me the
following code to copy the list of scouts names from one place, sort
it and paste it into another place but for some reason the sorting is
not working. Any suggestions?

Private Sub Workbook_Open()
Sheets("ScoutList08 & Sales-to-date").Select
Range("B2:B75").Select
Selection.Copy
Sheets("DataEntry").Select
Range("C5000").Select
ActiveSheet.Paste
Selection.Sort Key1:=Range("C5001"), Order1:=xlAscending,
Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A6").Select
End Sub

Cartoper