Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JCO JCO is offline
external usenet poster
 
Posts: 54
Default Sort Routine Macro for Excel Worksheet

I have an excel that requires a sort routine. I tried using the start/stop
recording. The code is shown below, however, I need this routine to work
when you don't know how many rows are in the data. My method has the
filename hardcoded too. I don't know if that matters. This one subroutine
of many. Can someone show me how to make this routine more dynamic. It
will always sort by the same Column but it needs to work with all different
Ranges of data (this example is hardcoded to sort data from row 2 through
row 613.

Sub SortCategoryAssistance()
Cells.Select
ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort.SortFields.Add
Key:= _
Range("P2:P613"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort
.SetRange Range("A1:T613")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
JCO JCO is offline
external usenet poster
 
Posts: 54
Default Sort Routine Macro for Excel Worksheet

never mind. I figured it out as shown below:
'
' SortCategoryAssistanceWithHeadersMacro
'
'
Cells.Sort Key1:=Range("P2"), _
Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
'
Range("A17").Select


"JCO" wrote in message
...
I have an excel that requires a sort routine. I tried using the
start/stop recording. The code is shown below, however, I need this
routine to work when you don't know how many rows are in the data. My
method has the filename hardcoded too. I don't know if that matters.
This one subroutine of many. Can someone show me how to make this routine
more dynamic. It will always sort by the same Column but it needs to work
with all different Ranges of data (this example is hardcoded to sort data
from row 2 through row 613.

Sub SortCategoryAssistance()
Cells.Select
ActiveWorkbook.Worksheets("NEEDWest Error
Report").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort.SortFields.Add
Key:= _
Range("P2:P613"), SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("NEEDWest Error Report").Sort
.SetRange Range("A1:T613")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub


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
Sort Routine Platinum girl[_2_] Excel Discussion (Misc queries) 0 March 9th 07 03:21 PM
Generalising sort routine lexcel Excel Programming 0 June 3rd 06 02:57 PM
sort and tally routine alvin Excel Programming 3 October 4th 05 01:50 PM
Sort Routine VBA weeper Excel Programming 2 September 29th 04 02:59 PM
Need a Special Sort Routine weeper Excel Programming 0 September 28th 04 07:49 PM


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