#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default sort macro

Hi,

Here's a sort macro I recorded. It works, but I'd like to change it to where
the bottom row it goes to (the column value is constant) is the last row
with content in column A.
================================
Sub Hospital_Sheet_Sort()
'
' Hospital_Sheet_Sort Macro
' Macro recorded 3/19/2005 by Randy Starkey
'

'
Range("A3:V361").Select
Range("V361").Activate
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("N3")
_
, Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:= _
xlSortNormal
Range("A3:A3").Select
End Sub
=================================

Could someone help me making that adjustment?

Thanks!

--Randy Starkey


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default sort macro

Sub Hospital_Sheet_Sort()
'
' Hospital_Sheet_Sort Macro
' Macro recorded 3/19/2005 by Randy Starkey
'

'
Range(Cells(3, 1), Cells(Cells(65536, 1).End(xlUp).Row, 22)).Sort _
Key1:=Range("A3"), _
Order1:=xlAscending, _
Key2:=Range("N3"), _
Order2:=xlDescending, _
Header:=xlNo, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom

End Sub

I have left DataOption1 etc. as I think this won't work with earlier
versions of Excel.


RBS

"Randy Starkey" wrote in
message ...
Hi,

Here's a sort macro I recorded. It works, but I'd like to change it to
where the bottom row it goes to (the column value is constant) is the last
row with content in column A.
================================
Sub Hospital_Sheet_Sort()
'
' Hospital_Sheet_Sort Macro
' Macro recorded 3/19/2005 by Randy Starkey
'

'
Range("A3:V361").Select
Range("V361").Activate
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending,
Key2:=Range("N3") _
, Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:= _
xlSortNormal
Range("A3:A3").Select
End Sub
=================================

Could someone help me making that adjustment?

Thanks!

--Randy Starkey


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default sort macro

Something like:

Option Explicit
Sub Hospital_Sheet_Sort()

Dim myRng As Range

With ActiveSheet
Set myRng = .Range("a3:V" & .Cells(.Rows.Count, "A").End(xlUp).Row)

myRng.Sort Key1:=.Range("A3"), Order1:=xlAscending, _
Key2:=.Range("N3"), Order2:=xlDescending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
End With

End Sub

This also avoids selecting any cells--and that's usually a good thing.

Just a word of warning. Those DataOption# were added in xl2002. If you think
you're going to need to use this in xl2k or below, remove them from the code.



Randy Starkey wrote:

Hi,

Here's a sort macro I recorded. It works, but I'd like to change it to where
the bottom row it goes to (the column value is constant) is the last row
with content in column A.
================================
Sub Hospital_Sheet_Sort()
'
' Hospital_Sheet_Sort Macro
' Macro recorded 3/19/2005 by Randy Starkey
'

'
Range("A3:V361").Select
Range("V361").Activate
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("N3")
_
, Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:= _
xlSortNormal
Range("A3:A3").Select
End Sub
=================================

Could someone help me making that adjustment?

Thanks!

--Randy Starkey


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default sort macro

Thanks much for both code samples! We use exclusively Office 2003 so the
earlier versions are not an issue.

--Randy Starkey


"Dave Peterson" wrote in message
...
Something like:

Option Explicit
Sub Hospital_Sheet_Sort()

Dim myRng As Range

With ActiveSheet
Set myRng = .Range("a3:V" & .Cells(.Rows.Count, "A").End(xlUp).Row)

myRng.Sort Key1:=.Range("A3"), Order1:=xlAscending, _
Key2:=.Range("N3"), Order2:=xlDescending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
End With

End Sub

This also avoids selecting any cells--and that's usually a good thing.

Just a word of warning. Those DataOption# were added in xl2002. If you
think
you're going to need to use this in xl2k or below, remove them from the
code.



Randy Starkey wrote:

Hi,

Here's a sort macro I recorded. It works, but I'd like to change it to
where
the bottom row it goes to (the column value is constant) is the last row
with content in column A.
================================
Sub Hospital_Sheet_Sort()
'
' Hospital_Sheet_Sort Macro
' Macro recorded 3/19/2005 by Randy Starkey
'

'
Range("A3:V361").Select
Range("V361").Activate
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending,
Key2:=Range("N3")
_
, Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
MatchCase:=False _
, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
DataOption2:= _
xlSortNormal
Range("A3:A3").Select
End Sub
=================================

Could someone help me making that adjustment?

Thanks!

--Randy Starkey


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default sort macro


Hello Randy,

REMOVE THIS:

Range("A:A").Select

USE THIS:

ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Select

Hope this helps,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=355849



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default sort macro

Leith,

My purpose in this statement was just to move the cursor to A3 after the
sort. Is it wrong?

Thanks!

--Randy

"Leith Ross" wrote in message
...

Hello Randy,

REMOVE THIS:

Range("A:A").Select

USE THIS:

ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Select

Hope this helps,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:
http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=355849



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 Macro sross002 Excel Discussion (Misc queries) 4 April 23rd 09 02:46 PM
Sort Macro FrankTimJr Excel Worksheet Functions 1 February 28th 09 06:33 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Using Macro to sort without clicking on macro button dd Excel Discussion (Misc queries) 3 May 3rd 07 06:00 PM
Sort Macro Sprinks Excel Discussion (Misc queries) 1 April 19th 05 04:58 PM


All times are GMT +1. The time now is 03:20 AM.

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"