Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default range selection for a sort on a excel db

I get an error on the Rows.Count line because I don't know how/what to select
for the range to sort on. Does it have to select the entire worksheet cells
in order to sort on the 3 keys or does it just need the top to bottom range
of 1 of the columns? Right now I selected the A1:

There are just 3 keys to sort on, Q1, S1, & A1 are the header fields. The
first two are ID numbers and A1 is alpha sort. This macro isn't sorting.

THANKS,


Sub Sort()
'
' Sorts by Item Name, Dept, Status# Macro
Dim rng As Range

' sorts on Dept, & Status since there is only 3 keys available in a sort
With ActiveSheet
Set rng = .Range(.Cells(1, 1), .Cells(27, 1))
(Rows.Count, "A").End(xlUp)

rng.Sort key1:=Cells(17, 2), Order1:=xlAscending, _
key2:=Cells(19, 2), Order2:=xlDescending, _
key3:=Cells(1, 2), Order3:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End With


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default range selection for a sort on a excel db

You can try this. The only thing tha tI notice is taht you probably want to
specify whether there is a header row instead of xlGuess. Change it to xlYes
or xlNo.

Sub Sort()
'
' Sorts by Item Name, Dept, Status# Macro
Dim rng As Range

' sorts on Dept, & Status since there is only 3 keys available in a sort
With ActiveSheet
Set rng = .Range(.Cells(1, 1), (Rows.Count, 27).End(xlUp))

rng.Sort key1:=Cells(17, 2), Order1:=xlAscending, _
key2:=Cells(19, 2), Order2:=xlDescending, _
key3:=Cells(1, 2), Order3:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End With

--
HTH...

Jim Thomlinson


"Janis" wrote:

I get an error on the Rows.Count line because I don't know how/what to select
for the range to sort on. Does it have to select the entire worksheet cells
in order to sort on the 3 keys or does it just need the top to bottom range
of 1 of the columns? Right now I selected the A1:

There are just 3 keys to sort on, Q1, S1, & A1 are the header fields. The
first two are ID numbers and A1 is alpha sort. This macro isn't sorting.

THANKS,


Sub Sort()
'
' Sorts by Item Name, Dept, Status# Macro
Dim rng As Range

' sorts on Dept, & Status since there is only 3 keys available in a sort
With ActiveSheet
Set rng = .Range(.Cells(1, 1), .Cells(27, 1))
(Rows.Count, "A").End(xlUp)

rng.Sort key1:=Cells(17, 2), Order1:=xlAscending, _
key2:=Cells(19, 2), Order2:=xlDescending, _
key3:=Cells(1, 2), Order3:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End With


End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default range selection for a sort on a excel db

Thanks Jim, you answered this before but there were 4 sorts now there are
only 3 so it got changed and I couldn't figure out how to do the range,

"Jim Thomlinson" wrote:

You can try this. The only thing tha tI notice is taht you probably want to
specify whether there is a header row instead of xlGuess. Change it to xlYes
or xlNo.

Sub Sort()
'
' Sorts by Item Name, Dept, Status# Macro
Dim rng As Range

' sorts on Dept, & Status since there is only 3 keys available in a sort
With ActiveSheet
Set rng = .Range(.Cells(1, 1), (Rows.Count, 27).End(xlUp))

rng.Sort key1:=Cells(17, 2), Order1:=xlAscending, _
key2:=Cells(19, 2), Order2:=xlDescending, _
key3:=Cells(1, 2), Order3:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End With

--
HTH...

Jim Thomlinson


"Janis" wrote:

I get an error on the Rows.Count line because I don't know how/what to select
for the range to sort on. Does it have to select the entire worksheet cells
in order to sort on the 3 keys or does it just need the top to bottom range
of 1 of the columns? Right now I selected the A1:

There are just 3 keys to sort on, Q1, S1, & A1 are the header fields. The
first two are ID numbers and A1 is alpha sort. This macro isn't sorting.

THANKS,


Sub Sort()
'
' Sorts by Item Name, Dept, Status# Macro
Dim rng As Range

' sorts on Dept, & Status since there is only 3 keys available in a sort
With ActiveSheet
Set rng = .Range(.Cells(1, 1), .Cells(27, 1))
(Rows.Count, "A").End(xlUp)

rng.Sort key1:=Cells(17, 2), Order1:=xlAscending, _
key2:=Cells(19, 2), Order2:=xlDescending, _
key3:=Cells(1, 2), Order3:=xlAscending, Header:=xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom
End With


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
Prevent SORT from asking to expand selection in Excel 2007? M. E. Kabay, PhD, CISSP-ISSMP Excel Discussion (Misc queries) 9 September 9th 19 04:13 PM
How do you do a range selection dialog like those many in Excel? LunaMoon Excel Discussion (Misc queries) 2 July 31st 08 04:22 PM
Excel 2007 Range Selection CM Excel Discussion (Misc queries) 2 February 28th 08 10:17 PM
excel change default column sort to current selection john palmer Excel Worksheet Functions 2 March 8th 05 03:07 PM
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. jonH Excel Programming 3 June 7th 04 09:13 PM


All times are GMT +1. The time now is 06:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"