Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Sorting data in Excel

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Sorting data in Excel

Hi Cartoper

I'm not sure what is going on for you as i tested this code and it
works fine for me running Excel 2003 on XP. It sorts the list after
it has been pasted to the DataEntry Sheet but other than that it does
exactly what you described.

Steve

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Sorting data in Excel

One mo

Option Explicit
Private Sub Workbook_Open()

Dim RngToCopy As Range
Dim DestCell As Range

Set RngToCopy = Worksheets("ScoutList08 & Sales-to-date").Range("B2:B75")

Set DestCell = Worksheets("DataEntry").Range("c5000")

RngToCopy.Copy _
Destination:=DestCell

With DestCell.Resize(RngToCopy.Rows.Count, RngToCopy.Columns.Count)
.Cells.Sort key1:=.Columns(1), Order1:=xlAscending, _
header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End With

Application.CutCopyMode = False

End Sub

I changed the xlGuess to xlYes. Since it's your data, I bet you know if it has
headers or not. I wouldn't let excel guess.



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


--

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
Sorting data in Excel Molli Excel Discussion (Misc queries) 2 November 8th 08 02:21 AM
Excel Data Sorting Cheryl Excel Worksheet Functions 4 October 8th 08 08:51 PM
sorting excel data [email protected] Excel Worksheet Functions 12 July 12th 07 02:32 PM
Sorting Excel Data artlawton New Users to Excel 2 June 8th 05 04:37 PM
Sorting data in Excel.. dan1001 Excel Worksheet Functions 1 March 1st 05 05:08 PM


All times are GMT +1. The time now is 04:00 PM.

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"