#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Giselle
 
Posts: n/a
Default sorting concern

Greetings XLers

I have a range that I need to sort in VB with code like:

Worksheets("Summary").Range("A4:T59").Sort
key1:=Worksheets("Summary").Range("J4"),
key2:=Worksheets("Summary").Range("C4")

Typically, there may be, say, 30 rows of data at the top of this range. All
30 rows will have a C value, but not all will have a J value.

After the first sort, the rows with no J value get pushed to the bottom of
the range. Instead, I'd like the sort result to look like this:

C J
Jones 12
Newt 15
Zack 15
Barr
Chen
blank row after this

I don't know if this approach is correct, but I'm trying to count the number
of entries in col C (eg 30), then adjust the range to be sorted accordingly
(eg A4:T33). I just can't get the code to work, and I don't know if there
is an easier approach.

TQ in advance

Giselle



  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default sorting concern

I use a helper column of cells with formulas that force blanks to the bottom of
the list:

=if(j2="",999999999,j2)
and then drag down and sort by that.

You could even do that kind of thing in your code (insert a new column U, add
the formula, sort by that column and then delete that inserted U column.)



Giselle wrote:

Greetings XLers

I have a range that I need to sort in VB with code like:

Worksheets("Summary").Range("A4:T59").Sort
key1:=Worksheets("Summary").Range("J4"),
key2:=Worksheets("Summary").Range("C4")

Typically, there may be, say, 30 rows of data at the top of this range. All
30 rows will have a C value, but not all will have a J value.

After the first sort, the rows with no J value get pushed to the bottom of
the range. Instead, I'd like the sort result to look like this:

C J
Jones 12
Newt 15
Zack 15
Barr
Chen
blank row after this

I don't know if this approach is correct, but I'm trying to count the number
of entries in col C (eg 30), then adjust the range to be sorted accordingly
(eg A4:T33). I just can't get the code to work, and I don't know if there
is an easier approach.

TQ in advance

Giselle


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Giselle
 
Posts: n/a
Default sorting concern

Thanks, Dave works fine


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 non contiguous ranges gsh20 Excel Discussion (Misc queries) 1 September 8th 05 04:50 PM
Advice sought: Multiple column sorting davidm Excel Worksheet Functions 3 July 29th 05 02:06 PM
Sorting 1, 1A, 2, 2A, 3, 4, 4A, 4B . . . agc1234 Excel Discussion (Misc queries) 6 May 26th 05 08:02 PM
sorting number in ascending order Janice Lee via OfficeKB.com Excel Discussion (Misc queries) 2 April 8th 05 10:31 PM
Adding a KeyID column for sorting Rebecca New Users to Excel 3 February 20th 05 07:09 PM


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