Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to auto hide rows if blank cells in a column?

If you have a range of data which populate some blank cells in a column, and now, you want to hide the rows which contain the blank cells in that column automatically. Are there any good ways to solve this job in Excel quickly and easily?

Auto hide rows if blank cells in a column with VBA code

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

arrow blue right bubble Auto hide rows if blank cells in a column with VBA code

The following code may help you to hide all rows if blank cells in a specific column at once, and if you delete the cell content in that column, the rows will be hide automatically, too. Please do as follows:

1. Right click at the sheet tab that you want to auto hide the rows if there are blank cells in a column , and then choose View Code from the context menu, in the popped out Microsoft Visual Basic for Applications window, please copy and paste the following code into the blank Module:

VBA code: Auto hide rows if blank cells in a column:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice 20160913
    Dim xRg As Range
    Application.ScreenUpdating = False
        For Each xRg In Range("A1:A20")
            If xRg.Value = "" Then
                xRg.EntireRow.Hidden = True
        
            Else
                xRg.EntireRow.Hidden = False
            End If
        Next xRg
    Application.ScreenUpdating = True
End Sub

doc auto hide rows 1

Note: In the above code, A1:A20 is the data list which contains the blank cells you want to auto hide.

2. Then go back to the worksheet, and now, when you double click any cell and press Enter key, the rows which contain blank cells in column A have been hide at once, and if you clear any cell content in the specified cells of column A, the rows will be hide automatically.

doc auto hide rows 2


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

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!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Josh · 8 months ago
    The formula works to hide cells based on information, at the beginning, but does not re-reveal cells if their content changes. I want it to reveal any new cells that have been filled with information (which occurs via a cell lookup). How do I do this?
  • To post as a guest, your comment is unpublished.
    ACHINTA PANDE · 9 months ago
    I want to know whether the code will work If the cell is blank as a result of Formula ?
    • To post as a guest, your comment is unpublished.
      skyyang · 9 months ago
      Hello, ACHINTA,
      The above VBA code is also applied to the blank cells as a result of formula, you could try it, thank you!
  • To post as a guest, your comment is unpublished.
    فتحى السعيد · 1 years ago
    بسم الله وجزاكم الله خيرا هذا الكود رائع ولكن حين قمت بتطبيق كود حذف الصف يبطأ الشيت بطريقة طويلة جدا فما العمل؟
  • To post as a guest, your comment is unpublished.
    chinmay salpe · 1 years ago
    how to Auto hide rows if blank cells in 2 different columns with VBA code
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi, salpe,
      To hide the rows if blank cells in 2 different columns automatically, please apply the following code:

      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim xRg, xCell As Range
      Dim xRgs, xRgArea As Range
      Set xRgs = Range("A1:A22,D1:D22")
      Application.ScreenUpdating = False
      On Error GoTo Ctn
      For Each xRgArea In xRgs.Areas
      Debug.Print xRgArea.Address
      For Each xRg In xRgArea.Columns
      For Each xCell In xRg.Rows
      If xCell.Value = "" Then
      xCell.EntireRow.Hidden = True
      GoTo Ctn
      ElseIf Not xCell.EntireRow.Hidden Then
      xCell.EntireRow.Hidden = False
      End If
      Ctn:
      Next
      Next
      Next
      Application.ScreenUpdating = True
      End Sub

      You can change the cell references to your need.
      Please try it!
  • To post as a guest, your comment is unpublished.
    alex · 2 years ago
    Can I stop this macro from running automatically after hitting enter? Could I attach it to a button to only hide the cells when I click?
    • To post as a guest, your comment is unpublished.
      devin · 1 years ago
      did anyone ever figure this out? I too would like to know.
      • To post as a guest, your comment is unpublished.
        Koop · 1 years ago
        anyone come up with the answer yet?
        • To post as a guest, your comment is unpublished.
          andrea · 1 years ago
          same question here
          • To post as a guest, your comment is unpublished.
            skyyang · 1 years ago
            Hello, guys,
            To hide the rows which a specific column contains blank cells by using a button, please do as this:
            First, you should insert a Command Button from the Developer tab.
            And then apply the following VBA code for the Command Button, (Note: please change the cell reference a1:a20 to your own)

            Private Sub CommandButton1_Click()
            Dim rng As Range, x As Range
            Set rng = Range("a1:a20")
            Application.ScreenUpdating = False
            For Each x In rng
            If Len(x.Text) = 0 Then
            x.EntireRow.Hidden = True
            Else
            x.EntireRow.Hidden = False
            End If
            Next x
            Application.ScreenUpdating = True
            End Sub

            Please try it, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Lars · 2 years ago
    I get a Run-time error ´13´:



    Type mismatch



    Someone who can help???
  • To post as a guest, your comment is unpublished.
    Ant · 2 years ago
    Hi, i am using excel 2016 and it s not working. I get a sintax error message. can you help?
    • To post as a guest, your comment is unpublished.
      skyyang · 2 years ago
      Hello, Ant,

      The above code works well in my Excel 2016, have you change the cell reference in the code to your need?