sort, blanks to bottom, even when resulting from a formula

Ken Cowen

Board Regular
Joined
Jan 18, 2015
Messages
217
When I sort my data by a column containing blank cells, the blanks go to the bottom regardless of whether I sort ascending or descending. I like that. When I have a column with a formula and the formula returns a blanks ("") in some cases, I would like those blanks to always be on the bottom. I have tried "" and " " but both sort to the top, unlike when the cells are just blank. Is there a way to control this behavior?

Thanks

Ken
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I cannot reproduce that behavior. I just tested with empty cells, and blanks being returned by formulas, and both sort to the bottom for me.
Can you post your formula?
And how many columns are you sorting by? (is it just one of multiple? is this columns the FIRST column in the column sort order?)
 
Upvote 0
This is the real formula

=IF(I3="Original","Original",IF(I3<>"","RCC "&TEXT(I3,"000")&L3,""))

I sort by only one column at a time, the data that is selected does not include a header row.

This is my test formula

=""

it gives the exact same result as the longer actual formula.

I want the blanks or those looking like blanks to stay on the bottom.

In actual use the sorting is typically triggered by double-clicking on a header row (not included in the sort range) to trigger the sort. It alternates between ascending and descending using the code below


Sub sortem(R, k)


'sort range R by column k, alternate ascending and descending order


If ord = False Then
R.Sort Key1:=Range(k), Order1:=xlAscending, Header:=xlNo
Else
R.Sort Key1:=Range(k), Order1:=xlDescending, Header:=xlNo
End If

ord = Not ord

End Sub

When I have blanks, which I do in several columns, they stay on the bottom, where they belong. A couple columns have formulas that often return blanks (like the sample above) and they alternate between being on the top and on the bottom.

Thanks

Ken
 
Upvote 0
OK. I see what you mean now.
However, it appears that if you sort in Descending order, it will then list all the blanks and empty cells at the end, like you want.
 
Last edited:
Upvote 0
Joe
I was really hoping to keep them at the bottom regardless of sort order, as if they were blank cells. I think what is missing is the ability to make the cells NULL. Apparently a NULL worksheet function is on microsoft's list of things to add; I guess I will just have to wait.
Thanks for your time and effort.
Ken
 
Upvote 0
The way I sorted blanks to bottom was to create a "cleaned" column that had the blanks replaced with zeroes. I used an if() with an isnumber() to replace them. If the column to sort with blanks is A and the "cleaned" columns is B, the cell B2 would have:

=IF(ISNUMBER(A2), A2, 0)

I then sorted the whole table by the cleaned column. Could easily do something similar with a negative value or even the minimum value of that column (just store that in a cell and make a fixed reference to that cell in the third argument to the IF() call.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top