Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default sort a table that contains both numbers and blank cells

I have a table that contains both numbers and blank cells, when I sort this
table I first have to do it in ascending order so that the nonblank cells end
up on top, and then I sort again in descending order by highlighting only the
nonblank cells (which are now on top). I want create a macro for this table
so that it will sort automatically but I can't do it because it always puts
the blank cells on top. Is there a way to sort, in descending order, so that
numbers are on top and blank cells are on the bottom?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default sort a table that contains both numbers and blank cells

Say we have a table from C7 thru F20 like:

first sec thir fou
30 622 679 169
3593 934 876 291
2814 501 247 770
939 532 71
4247 818 137 456
9674 917 153 1
4052 754 502 378
40 26 338
6744 14 979 387
9568 502 441 391
27 429 733
7694 203 507 861
4075 55 701 306

running the following macro:

Sub Macro1()

Range("C7:F20").Select

Selection.Sort Key1:=Range("C8"), Order1:=xlDescending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

For i = 20 To 7 Step -1
If Range("C" & i).Value < "" Then Exit For
Next

If i = 7 Then i = 17

Range("C7:F" & i).Select

Selection.Sort Key1:=Range("C8"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

will produce:

first sec thir fou
30 622 679 169
2814 501 247 770
3593 934 876 291
4052 754 502 378
4075 55 701 306
4247 818 137 456
6744 14 979 387
7694 203 507 861
9568 502 441 391
9674 917 153 1
939 532 71
40 26 338
27 429 733

--
Gary''s Student - gsnu200907


"slickedge52" wrote:

I have a table that contains both numbers and blank cells, when I sort this
table I first have to do it in ascending order so that the nonblank cells end
up on top, and then I sort again in descending order by highlighting only the
nonblank cells (which are now on top). I want create a macro for this table
so that it will sort automatically but I can't do it because it always puts
the blank cells on top. Is there a way to sort, in descending order, so that
numbers are on top and blank cells are on the bottom?

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
Why is a descending sort putting blank cells first? Romileyrunner1 Excel Worksheet Functions 5 October 1st 09 09:46 AM
sort and blank cells problem Mrs T.[_2_] Excel Worksheet Functions 4 May 6th 09 08:27 PM
Sort when I have blank cells C. Corodan Excel Discussion (Misc queries) 1 August 6th 08 01:20 PM
sort and sum data range with some blank cells rldjda Excel Worksheet Functions 1 March 23rd 08 06:19 AM
Why arent my blank cells moved to the end when I do a sort? George New Users to Excel 3 May 31st 06 09:34 PM


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