Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default VBA to sort blank cells to bottom <--help please :o)

Hello -

I have the following code which, I think, will sort my spreadsheet
from row 5 down by column I.

Worksheets("JCW").Range("A4:M65536").Sort _
Key1:=Worksheets("JCW").Range("i5"), Order1:=xlDescending,
Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers

2 problems...
1) All of the blank cells go to the top of the list, I would like
these on the bottom
2) I defined the entire workbook as a range, can the code be written
to only sort what is actually on the worksheet?

Thanks for any assistance,
Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default VBA to sort blank cells to bottom <--help please :o)

Hello Dan

Try this

With Worksheets("JCW")
Set LastCell = .Range("M65536").End(xlUp)

' Sort "ascending" to force empty cells to bottom
.Range("A4", LastCell).Sort Key1:=.Range("i5"),
Order1:=xlAscending, Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortTextAsNumbers

'Resize your data area, then sort descending
Set LastCell = .Range("M65536").End(xlUp)
Range("A4", LastCell).Sort Key1:=.Range("i5"),
Order1:=xlDescending, Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortTextAsNumbers
End With

Regards

Per

On 14 Dec., 02:31, Dan wrote:
Hello -

I have the following code which, I think, will sort my spreadsheet
from row 5 down by column I.

Worksheets("JCW").Range("A4:M65536").Sort _
Key1:=Worksheets("JCW").Range("i5"), Order1:=xlDescending,
Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers

2 problems...
1) All of the blank cells go to the top of the list, I would like
these on the bottom
2) I defined the entire workbook as a range, can the code be written
to only sort what is actually on the worksheet?

Thanks for any assistance,
Dan


  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default VBA to sort blank cells to bottom <--help please :o)

On Dec 13, 6:52 pm, Per Jessen wrote:
Hello Dan

Try this

With Worksheets("JCW")
Set LastCell = .Range("M65536").End(xlUp)

' Sort "ascending" to force empty cells to bottom
.Range("A4", LastCell).Sort Key1:=.Range("i5"),
Order1:=xlAscending, Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortTextAsNumbers

'Resize your data area, then sort descending
Set LastCell = .Range("M65536").End(xlUp)
Range("A4", LastCell).Sort Key1:=.Range("i5"),
Order1:=xlDescending, Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortTextAsNumbers
End With

Regards

Per

On 14 Dec., 02:31, Dan wrote:



Hello -


I have the following code which, I think, will sort my spreadsheet
from row 5 down by column I.


Worksheets("JCW").Range("A4:M65536").Sort _
Key1:=Worksheets("JCW").Range("i5"), Order1:=xlDescending,
Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers


2 problems...
1) All of the blank cells go to the top of the list, I would like
these on the bottom
2) I defined the entire workbook as a range, can the code be written
to only sort what is actually on the worksheet?


Thanks for any assistance,
Dan- Hide quoted text -


- Show quoted text -


I appreciate the help Per. Thank you.

Dan
  #4   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default VBA to sort blank cells to bottom <--help please :o)

On Dec 13, 6:52 pm, Per Jessen wrote:
Hello Dan

Try this

With Worksheets("JCW")
Set LastCell = .Range("M65536").End(xlUp)

' Sort "ascending" to force empty cells to bottom
.Range("A4", LastCell).Sort Key1:=.Range("i5"),
Order1:=xlAscending, Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortTextAsNumbers

'Resize your data area, then sort descending
Set LastCell = .Range("M65536").End(xlUp)
Range("A4", LastCell).Sort Key1:=.Range("i5"),
Order1:=xlDescending, Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortTextAsNumbers
End With

Regards

Per

On 14 Dec., 02:31, Dan wrote:



Hello -


I have the following code which, I think, will sort my spreadsheet
from row 5 down by column I.


Worksheets("JCW").Range("A4:M65536").Sort _
Key1:=Worksheets("JCW").Range("i5"), Order1:=xlDescending,
Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers


2 problems...
1) All of the blank cells go to the top of the list, I would like
these on the bottom
2) I defined the entire workbook as a range, can the code be written
to only sort what is actually on the worksheet?


Thanks for any assistance,
Dan- Hide quoted text -


- Show quoted text -


Per - I've tried this code and it sorts everything but still leaves
the blank cells on the bottom. Both of the sections of code you
provided seem to be the same, could this be the problem?

Thanks again,
Dan
  #5   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default VBA to sort blank cells to bottom <--help please :o)

On Dec 13, 6:52 pm, Per Jessen wrote:
Hello Dan

Try this

With Worksheets("JCW")
Set LastCell = .Range("M65536").End(xlUp)

' Sort "ascending" to force empty cells to bottom
.Range("A4", LastCell).Sort Key1:=.Range("i5"),
Order1:=xlAscending, Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortTextAsNumbers

'Resize your data area, then sort descending
Set LastCell = .Range("M65536").End(xlUp)
Range("A4", LastCell).Sort Key1:=.Range("i5"),
Order1:=xlDescending, Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom,
DataOption1:=xlSortTextAsNumbers
End With

Regards

Per

On 14 Dec., 02:31, Dan wrote:



Hello -


I have the following code which, I think, will sort my spreadsheet
from row 5 down by column I.


Worksheets("JCW").Range("A4:M65536").Sort _
Key1:=Worksheets("JCW").Range("i5"), Order1:=xlDescending,
Header:= _
xlYes, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers


2 problems...
1) All of the blank cells go to the top of the list, I would like
these on the bottom
2) I defined the entire workbook as a range, can the code be written
to only sort what is actually on the worksheet?


Thanks for any assistance,
Dan- Hide quoted text -


- Show quoted text -


All is good now, thanks for the help Per.

Dan
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
Apply bottom border only on filled cells, leaves blank cells without border? StargateFan[_3_] Excel Programming 4 April 8th 07 05:39 PM
sort blank cells first instead of last Paul Simon[_2_] Excel Programming 3 September 10th 03 12:06 AM


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

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"