Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Different way to sort?

I thought I had everything working properly in this weekends project. Tonight,
I imported the weekly csv, and now I have another problem:

When I'm finished with everything, the last step is to sort it all based on 3
columns.

I recorded a macro to do that, shown below. I see the problem now is when I
record it, it throws in values like "Y11290". I don't want it to be Y11290,
because if next weeks file is 15,000 lines long, it won't all get sorted. How
do I change this so that it always sorts on all of the data?

Thanks in advance.

Columns("A:AD").Select
Range("AD1").Activate
ActiveWorkbook.Worksheets("import").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("import").Sort.SortField s.Add Key:=Range( _
"AD2:AD11290"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("import").Sort.SortField s.Add Key:=Range( _
"F2:F11290"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("import").Sort.SortField s.Add Key:=Range( _
"Y2:Y11290"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("import").Sort
.SetRange Range("A1:AD9325")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Different way to sort?

Untested

Dim LastRow As Long

Columns("A:AD").Select
Range("AD1").Activate
LastRow = Cells(Rows.Count, "AD").End(xlUp).Row
With ActiveWorkbook.Worksheets("import")

.Sort.SortFields.Clear
.Sort.SortFields.Add _
Key:=Range("AD2").Resize(LastRow - 1), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Sort.SortFields.Add _
Key:=Range("F2").Resize(LastRow - 1), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.Sort.SortFields.Add _
Key:=Range("Y2").Resize(LastRow - 1), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
With .Sort
.SetRange Range("A1").Resize(LastRow - 1)
.Header = xlYes
.SortMethod = xlPinYin
.Apply
End With
End With

--
__________________________________
HTH

Bob

<Melvin Purvis wrote in message
...
I thought I had everything working properly in this weekends project.
Tonight,
I imported the weekly csv, and now I have another problem:

When I'm finished with everything, the last step is to sort it all based
on 3
columns.

I recorded a macro to do that, shown below. I see the problem now is when
I
record it, it throws in values like "Y11290". I don't want it to be
Y11290,
because if next weeks file is 15,000 lines long, it won't all get sorted.
How
do I change this so that it always sorts on all of the data?

Thanks in advance.

Columns("A:AD").Select
Range("AD1").Activate
ActiveWorkbook.Worksheets("import").Sort.SortField s.Clear
ActiveWorkbook.Worksheets("import").Sort.SortField s.Add Key:=Range( _
"AD2:AD11290"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("import").Sort.SortField s.Add Key:=Range( _
"F2:F11290"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("import").Sort.SortField s.Add Key:=Range( _
"Y2:Y11290"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("import").Sort
.SetRange Range("A1:AD9325")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With



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
Updating workbook with an alpha sort sheet and a numeric sort shee cjlatta Excel Discussion (Misc queries) 2 January 28th 09 12:00 AM
sort function for dates does not sort properly in Office 2007 Exc. Rosalie Excel Worksheet Functions 1 November 22nd 07 10:25 PM
Pls. reply Sort Data and copy to next coulmn when sort order chang shital shah Excel Programming 1 August 19th 05 02:51 PM
Excel sort by Fill Color by custom list sort Dash4Cash Excel Discussion (Misc queries) 2 July 29th 05 10:45 PM
sort (on part of) string - originally posted under Tricky Sort Tom Ogilvy Excel Programming 0 August 6th 04 02:42 AM


All times are GMT +1. The time now is 11:50 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"