How to Sort Data but Keep Blank Cells in Excel

In daily work, if we sort data with blank cells included in the same column, these blank cells are listed at the bottom automatically after sorting. If we want to keep the positions of these blank cells unchanged and only sort the others, how can we do that? In this article, we will show you the way to sort data in this scenario.

EXAMPLE

          ->         

There are two blank rows listed in above table. We want to sort data by score column with the two blank rows locked in row 5 and row 9. Normally, if we select score column and directly click sort “Z to A” button to sort data, the two blank cells are listed at the bottom, this behavior is not our expectation.

In fact, if we want to sort data with blank cells locked in their own positions, we can hide them firstly, then sort data in visible cells. After sorting data by proper order, we can unhide the hidden rows, the blank cells are still listed there.

STEPS

a. Select range A2:B13, then click Home in the ribbon, in Editing section click Find & Select button to see options for finding texts in document.

b. Click Go To Special option.

c. In Go To Special dialog, check on “Blanks” option. Options in this dialog are exclusive. Then click OK button.

d. After clicking OK, all blank cells are highlighted.

e. Keep blank cells highlighted. Press Ctrl+9 to hide rows. In Excel, Ctrl+9 can hide rows with cell or range highlighted. If you want to unhide rows, you can press Ctrl+Shift+9. If you want to hide columns instead of rows, you can press hotkey Ctrl+0.

f. Now, select B2:B13 with blank rows hidden, click Data in the ribbon, click Sort Largest to Smallest button in Sort & Filter section to sort numbers in B2:B13 from the largest to smallest.

g. After sorting, numbers are sorted from the largest to smallest properly.

h. Select entire rows from row 2 to row 13, right click to load row editing menu, click Unhide.

Blank cells (rows) are still listed there.

 

Related Posts

If Cell is This Value or That Value

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the result of logical test. If you want to see if a cell is A or B, and if one of ...

If Value is Greater Than A Certain Value
If Value is Greater Than A Certain Value 1

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the logical test result. If you want to see if a value in one cell is greater than a specific value, ...

If Cell is Not Blank
If Cell is Not Blank 6

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the result of created logical test. If you want to see if a cell is blank or not, and leave some ...

VBA Macro For VLOOKUP From Another Sheet
vba macro for vlookup from another sheet1

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you how to use VBA code to vlookup data ...

If Cell is Blank
If Cell is Blank_1

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the result of created logical test. If you want to see if a cell is blank or not, and leave some ...

If Cell Equals Certain Text String
If cell equals certain text_1

IF function is frequently used in Excel worksheet to return you expect “true value” or “false value” based on the result of created logical test. If you want to see if cell equals a certain text string like “Win”, you ...

If Cell Contains Either Text1 or Text2
If cell contains text1 or text2_1

IF function is frequently used in Excel worksheet to return “true value” or “false value” based on the logical test result. If you want to see if cell contains certain substring1 like “abc” or substring2 like “def”, and returns true ...

If Cell Contains Certain Text OR Equals Certain Text

IF cell equals certain text IF function is frequently used in Excel worksheet to return “true value” or “false value” based on the logical test result. If you want to test values to see if they equal certain text like ...

VLOOKUP From Another Sheet Not Working
vlookup from another sheet not working3

In the previous post, you should know that how to fix or remove the #N/A error when using VLOOKUP formula to lookup value from another sheet. And this post will show you reasons why your VLOOKUP formula is not working ...

If Cell Begins with One of Three Supplied Characters
If Cell Begins with One of Three Supplied Characters

If you want to test values to see if they begin with some given specific characters like “x”, ”y”, or “z”, you can create a formula with COUNTIF and SUM functions to return results. EXAMPLE You can see “TRUE” or ...

Sidebar