Skip to main content
 

How to sort rows to put the blank cells on top in Excel?

Author: Xiaoyang Last Modified: 2024-09-05

If you have a list of data which is populated with some blank cells, now, you need to sort all the empty cells on top of the data. When you apply the Sort feature in Excel, both the Sort Smallest to Largest and Sort Largest to Smallest functions will sort the blank cells at the bottom of the records. In this case, the following tutorial will talk about how to sort rows and put the blank cells on top in Excel.

Sort rows to put the blank cells on top by sorting colored cells
Easily sort rows to put the blank cells on top with Kutools for Excel

Sort rows to put the blank cells on top with a helper column
Sort rows to put the blank cells on top with VBA code


Sort rows to put the blank cells on top by sorting colored cells

In Excel, you can sort data by background color, so here, you can fill the blank cells with a specific color, and then sort them by color. Please do with the following steps:

1. Select your list of data, and press Ctrl + G to open the Go To dialog, then click Special button, see screenshot:

click Special button in the Go To dialog box

2. In the popped Go To Special dialog box, check Blanks option, and then click OK.

check Blanks option in the dialog box

3. And all the empty cells have been selected, now you can fill them with a color by clicking Home > Fill Color and selecting a color you want as following screenshot shown:

fill the blank cells with a color

4. Then you can sort the list by filling color, please select your values and click Data > Sort, in the popped Sort dialog, select the column that you want to sort, and choose Cell Color from the Sort On drop down list, then click the color of the blank cells, finally, choose On Top option. See screenshot:

sort data based on the color in the Sort dialog box

5. After finishing the settings, click OK, all the colored blank cells have been sorted first, then you can remove the color after sorting. See screenshots:

all the colored blank cells have been sorted first arrow right remove the color after sorting

Easily sort rows to put the blank cells on top with Kutools for Excel

The Advanced Sort utility of Kutools for Excel can help you easily sort rows and put the blank cells on top in Excel. Please do as follows.

Kutools for Excel offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Enhanced with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

1. Select the range you want to sort and put the blank cells on top, and then click Kutools Plus > Sort > Advanced Sort

click Advanced Sort feature of kutools

2. In the Advanced Sort dialog box, select your sorting condition, and then check the Blank cells in front box, and finally click the OK button. See screenshot:

check the Blank cells in front box in the dialog box

Then the selected range is sorted and all blank cells are put on top immediately as the below screenshot shown. 

all blank cells are put on top

  If you want to have a free trial (30-day) of this utility, please click to download it, and then go to apply the operation according above steps.


Sort rows to put the blank cells on top with a helper column

To sort the blank cells at the top of your data list, you can use a formula to identify the blanks, and then apply the Sort function.

1. In a blank cell which next to the data, cell B1, for instance, type this formula =A1="",see screenshot:

enter a formula to identify the blanks

2. Then drag the fill handle over to the cells that you want to contain this formula, and all the blank cells displayed as TRUE, and others as False, see screenshot:

drag the formula down to other cells

3. Then click Data > Sort Largest to Smallest, and a Sort Warning dialog will pop up, then check Expand the selection, see screenshots:

click Data > Sort Largest to Smallest
arrow down
check Expand the selection in the dialog box

4. And then click OK, all the blank cells have been sorted on the top of the values.

all the blank cells have been sorted on the top

5. At last, you can delete the values in helper column B as your need.


Sort rows to put the blank cells on top with VBA code

Apply the following VBA code, you can quickly sort the blank cells on top of the data.

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Sort the blank cells on top of the data

Sub SortBlankOnTop()
'Update 20140318
On Error Resume Next
Dim WorkRng As Range
Dim xMin As Double
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xMin = Application.WorksheetFunction.Small(WorkRng, 1) - 1
WorkRng.SpecialCells(xlCellTypeBlanks) = xMin
WorkRng.Sort , Key1:=Cells(WorkRng.Row, WorkRng.Column), Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
WorkRng.Replace What:=xMin, Replacement:="", LookAt:=xlWhole
End Sub

3. Then press F5 key to run this code, in the popped dialog, select the data range that you want to sort, see screenshot:

vba code to select the data list

4. And then click OK, the empty cells have been sorted on top.


Related articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!