Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Delete Rows in Excel if Completely Empty


Bookmark and Share

This macro will delete only completely blank rows in an excel spreadsheet. It allows you to make a selection of rows, run the macro, and then will delete only rows that have no data.

This is a great macro if you receive data that has only some empty cells but the columns next to the empty cells are still important.
Where to install the macro:  Module

Delete Completely Blank Rows

Public Sub DeleteCompletelyBlankRows()

Dim R As Long
Dim C As Range
Dim N As Long
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
N = 0
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).EntireRow) = 0 Then
Rng.Rows(R).EntireRow.Delete
N = N + 1
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

Completely Crazy =delete Rows If - Excel

View Content
I have 24 worksheets..
All are named in the same manner...

"AISLE A EVEN"
"AISLE A ODD"

Through AISLE L ( So A-L ).

Here goes nothing...
For every sheet, I need to delete any row that meets these 2 criteria:

Col E The Aisle's worksheet "aisle"
Col H The Aisle's worksheet EVEN ( or odd ).

This will be mind blowing.... if someone can crack it....

So a run-down...
On the worksheet "Aisle A EVEN"
It will delete any row that Col E A, and Col H EVEN
and so forth...

How Do I Delete Empty Rows In Excel? - Excel

View Content
e.g.:

B A O P
Q L P E
Q D L E

if i press Ctrl+End, it will jump to the E at bottom right corner
then
i delete the last row(entire)
and press Ctrl+End, it jumps to the empty space(previously the last "E")
how can I solve that problem?
thx a lot!


Vba To Delete Empty Rows And Rows That Have Empty Cell In A Specific Column - Excel

View Content
I'm trying to delete the empty rows as well as the rows that have empty cell in specific column?

Autofilter/delete Empty Rows Is Deleting Non-empty Rows! - Excel

View Content
Greetings, I'm currently running this code when the sheet deactivates to delete empty rows from a worksheet:

Code:

Private Sub Worksheet_Deactivate()
Application.ScreenUpdating = False
Sheets("Records").Unprotect Password:="secret"

With Worksheets("Records")
    .AutoFilterMode = False
    With Range("B2", Range("B" & Rows.Count).End(xlUp))
        .AutoFilter 1, "*Nil*"
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.Delete
    End With
    Sheets("Records").AutoFilterMode = False
End With

Sheets("Records").Protect Password "secret"
Application.ScreenUpdating = True
End Sub


The problem is, if there are less than two records in the worksheet, it will delete the heading row, breaking my dynamic named ranges and tables based on same.

I tried adding a check like this:
Code:

If ActiveSheet.UsedRange.Rows.Count < 3 Then Exit Sub


But this doesn't seem to work. Appreciate code / ideas to help!

EDIT: I should add that a new row is generated automatically when the last record has been completed, in anticipation of the user needing to enter another record. But if they don't actually need to enter anything, then I have to remove that blank row so that my dynamic named ranges don't include it in the range, thus messing up tables/pivot tables.

Delete Empty Rows When All Columns Of Row Are Empty - Excel

View Content
Could someone please tell me how to delete all empty rows in a spread sheet? I would like the rows to be deleted ONLY if ALL columns in the row are empty.

Thank you!

Delete Empty Rows - Excel

View Content
Hi, someone on this board helped me with the macro below, basically it's deleting the row (only 1 row) above the "custom table" rows, it worked the the other day, but not sure when i put it in a new file, it's not working properly. could someone advise on this? thanks much!
Code:

Sub DelEmptyRowAboveCustomTables()
'this macro should delete one row above each "custom tables", good luck!
Dim LastRow As Long, i As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
    For i = 1 To LastRow
        With Cells(i, "A")
            If .Value = "Custom Tables" And .Offset(2).Value Like "Table*" Then
                .Offset(-1).EntireRow.Delete
            End If
        End With
    Next i
Application.ScreenUpdating = True
End Sub




How Delete Rows When Value Is Empty - Excel

View Content
Hi !
How to delete activerow + two second rows ?

examble A colunm B column
row 1 Hold
2
3

row 1 hold
2 aasas (Don't delete and find next HOLD)
3




First I have to find "Hold" from B column and then lookup is the value A column second row empty ,if it's empty then delete all tree rows and then find Hold from column B and do the same.
Values in column B should be somenthing else than Hold

Br
Timo

Delete Empty Rows - Excel

View Content
Hi,

I have the following procedure which will delete entirely empty rows. However I only want to delete the row if every cell after column B is empty. I can't figure out how to modify the code to do this.

The code... Code:

Sub DelEmptyRows()
    Dim i As Long, lngLimit As Long

    lngLimit = ActiveSheet.UsedRange.Rows.Count
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    For i = lngLimit To 1 Step -1
        If Application.CountA(Cells(i, 1).EntireRow) = 0 Then
            Cells(i, 1).EntireRow.Delete
        End If
    Next i

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    lngLimit = ActiveSheet.UsedRange.Rows.Count   'attempt to fix lastcell
    ActiveWorkbook.Save
End Sub


Any help would be appreciated.

Regards,

Vba To Delete Empty Rows - Excel

View Content
Hi,

I am trying to delete rows that are zero or blank. I am not sure why the various VBA codes I have tried doesn't work. It may have to do with the cells having formulas.

In the attached file excerpt, I am trying to delete rows with zero or blank in column P. However, column P has formulas.

The actual sheet would have over 6,500 rows.

Thanks.

Delete Empty Rows - Excel

View Content
Does anyone know how I can delete empty rows using VBA?

Thanks in advance.

Random Tutorials
FV() Find the Future Value of Cash Today
         -Savings/Retirement Plan Calculations

(Intermediate)
HLOOKUP() Function - Introduction
(Intermediate)
Function and Formulas Lookup in Excel
(Easy)
Absolute and Relative Cell References
   - & INDIRECT() Function Introduction

(Easy)
Consolidate & Combine Data from Separate Worksheets or Workbooks(Excel Files)
(Intermediate)
How to record a Macro - And what One is
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com