Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Question about sorting and "key" range values

I have a simple sort I wish VBA to accomplish. The code looks something
like this:

Range("Database").Select
Selection.Sort Key1:=Range("???"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

Range("A1").Select

The only problem is that my Key1 range [Key1:=Range("???")] will not always
be in the same column depending on what table I'm working with. However, I
do have a variable SortColumn (an integer) that indicates what column my
sort key is in, and I also have a variable SortHeader (string) that
indicates what column header I wish to sort by. SortColumn will always be
the column number that SortHeader is in, obtained through another bit of
simple code. Can either of these variables be used in place of the ??? in
the key range? At the moment I don't have access to Excel, otherwise I'd
test this myself. Does this make any sense?

All suggestions welcome. Thanks!

-gk-



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Question about sorting and "key" range values

Range("Database").Select
Selection.Sort Key1:=Cells(selection.Row,SortColumn), _
Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

assume sortcolumn is the absolute column number (J would be 10 for
instance).

--
Regards,
Tom Ogilvy


TBA wrote in message
...
I have a simple sort I wish VBA to accomplish. The code looks something
like this:

Range("Database").Select
Selection.Sort Key1:=Range("???"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

Range("A1").Select

The only problem is that my Key1 range [Key1:=Range("???")] will not

always
be in the same column depending on what table I'm working with. However,

I
do have a variable SortColumn (an integer) that indicates what column my
sort key is in, and I also have a variable SortHeader (string) that
indicates what column header I wish to sort by. SortColumn will always be
the column number that SortHeader is in, obtained through another bit of
simple code. Can either of these variables be used in place of the ??? in
the key range? At the moment I don't have access to Excel, otherwise I'd
test this myself. Does this make any sense?

All suggestions welcome. Thanks!

-gk-





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Question about sorting and "key" range values

SortColumn varies between 1 and 255. It's the actual column number?

key1:=cells(1,sortcolumn)

might work ok.

(excel is very forgiving, but that column better intersect with the range to get
sorted someplace.)


TBA wrote:

I have a simple sort I wish VBA to accomplish. The code looks something
like this:

Range("Database").Select
Selection.Sort Key1:=Range("???"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom

Range("A1").Select

The only problem is that my Key1 range [Key1:=Range("???")] will not always
be in the same column depending on what table I'm working with. However, I
do have a variable SortColumn (an integer) that indicates what column my
sort key is in, and I also have a variable SortHeader (string) that
indicates what column header I wish to sort by. SortColumn will always be
the column number that SortHeader is in, obtained through another bit of
simple code. Can either of these variables be used in place of the ??? in
the key range? At the moment I don't have access to Excel, otherwise I'd
test this myself. Does this make any sense?

All suggestions welcome. Thanks!

-gk-


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Question about sorting and "key" range values

Both methods worked, thanks Tom and Dave!

-gk-

"Dave Peterson" wrote in message
...
SortColumn varies between 1 and 255. It's the actual column number?

key1:=cells(1,sortcolumn)

might work ok.

(excel is very forgiving, but that column better intersect with the range

to get
sorted someplace.)



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 a text strings but omitting preceding "A" or "The" Pablo Excel Worksheet Functions 2 December 15th 09 10:10 PM
Sorting by "High", "Medium" and "Low" MEGray Excel Discussion (Misc queries) 6 November 5th 09 09:41 PM
How do I get Excel to ignore "a", "an", "the" when sorting? Sedro6 Excel Discussion (Misc queries) 1 March 28th 09 11:09 PM
combining values and text to make a reference for "named range" devo.uk Excel Worksheet Functions 4 June 10th 08 10:31 AM
Changing "returned" values from "0" to "blank" LATATC Excel Worksheet Functions 2 October 20th 05 04:41 PM


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