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 Blank Rows in Excel


Bookmark and Share

This is a macro which will delete blank rows in excel. This version will delete an entire row if there is a blank cell detected in the column which you select.

This works by having a message box pop up in excel and then asking you how many rows, below and including the cell you selected, you want to check for and delete if it contains an empty cell within that column.

This macro for excel works very well; though, note that you will have to input, in the automated message box, the number of rows down that you want to check for.
Where to install the macro:  Module

Delete Blank Rows in Excel

Sub DeleteEmptyRows()
'
'This macro will delete all rows, which are missing data in a
'particular column, underneath and including the selected cell.
'
Dim Counter
Dim i As Integer

Counter = InputBox("Enter the total number of rows to process")
ActiveCell.Select
For i = 1 To Counter
If ActiveCell = "" Then
Selection.EntireRow.Delete
Counter = Counter - 1
Else
ActiveCell.Offset(1, 0).Select
End If

Next i

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

Would Like To Delete Rows With Blank Cell. But Excel Thinks It Is Not Blank Is Blank But Excel Thinks It Is Not - Excel

View Content
Enigma: there are cells in my workbook that are "blank" even when you hover the mouse over the cell the formula bar is blank. However when I print the page I get 8 blank pages. When I go to print preview the cells are blank but excel thinks that it is used so it is not blank.
when I use formula -=isblank(G9) it returns a FALSE VALUE. But it is actually empty.
I created this formula to delete blank cells in volums G and H but my macro is bombing.

Sub Macro1()
'
' Macro1 Macro
'
Dim wks As Worksheet
For Each wks In Worksheets
Columns("G:H").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete
Next wks
End Sub

It works on a few sheets and then ingnore other sheets in the workbook.
Can someone point me in the right direction?
Thanks

Auto Delete Blank Rows In Excel - Excel

View Content
Hi All

Is there a way to auto delete blank rows in Excel...or maybe using SQL?

Is There A Way To Delete Rows In Excel Where The First 3 Cells Are Blank? - Excel

View Content
Hi, i have downloaded an txt file to excel and i only need certain rows, there are misc rows below the ones i need where the first three cells are always blank, id like to delete those rows entireley, if i sort the file it still takes a while because then i have to look thru it i was wondering if there was an easier way? (maybe, maybe not?) to automatically delete all rows where the first three cells are empty??
see attached image below

Use Sorting To Delete Blank Rows In Excel 2007 - Excel

View Content


1. Select a cell in a List.
2. Select Home -> Sort & Filter (in Editing Group) -> Sort Smallest to Largest.


Befo

After:


Excel 2003 - Macro To Find Page Range And Delete All Blank Rows - Excel

View Content
We need to export a check history report from Quickbooks Enterprise into Excel 2003 and Excel 2007 (XP OS). The number of pages to each report will vary in length depending on how many checks were run during a given month and how many rows it takes to list the details of the checks.

The report inserts blank rows between the checks, which we need to be able to delete in order to condense it to a minimal number of pages.

I have no experience with macros, however I catch on quickly and have done so in Adobe Acrobat with java scripting.

I would like to know if you can provide for me a macro that will find the page range of the report and then find and delete all blank rows within the report.

I know I will need to work with VB and I copied one macro that I saw on this forum into VB but the specific macro did not work properly for me in my test. However, I am using Excel 2010, which may make a difference as to how the macro is set up.

If Excel 2003 and/or 2007 work similarly to 2010, I believe I understand how to set up the macro using VB and where to save it so it is accessible for any workbook created in Excel, but I need the proper wording to enter so I can test it out.

Thank you in advance for any help you can give me. I hope I don't sound too ignorant on this!

Excel Doesnt Recognize Last Used Cell (how To Delete Blank Rows At Bottom Of Sheet) - Excel

View Content
I've searched through threads back to 2005 and couldn't find the answer without downloading a plug-in like ASAP Utilities (which I cannot do due to work restrictions). (Marc's thread about "all I did was insert 50 rows and everything went to hell" was a great read, BTW! )

So here I am, looking for advice on what I would think is an easy solution to a simple problem...

When I hit CTRL+END to get to the bottom of the sheet to add new data it selects the cell at 65536. I want it to go to the last row I've got data in. Or more accurately, the next cell down.

I've tried selecting all the rows down and deleting them, but it's not working, and I can't download/run anything external.

Is there a fix I can use programatically? Via options? A formula? Anything? I'm in and out of this "database" many times a day and I'm really getting tired of the extra keystroks I'm having to do when I'm used to hitting CTRL+END and going from there.

Thanks in advance.

How To Delete Multiple Consecutive Blank Rows But Leave With One Blank Row - Excel

View Content
Please Help me with some macro. I have tried hard but failed.

All I want is to - Delete Multiple Consecutive Blank Rows but leave with One Blank Row.

For eg:

ozgrid.com
ozgrid.com
.
.
.
ozgrid.com
.
.
ozgrid.com
ozgrid.com
ozgrid.com
.
ozgrid.com

Should be like:

ozgrid.com
ozgrid.com
.
ozgrid.com
.
ozgrid.com
ozgrid.com
ozgrid.com
.
ozgrid.com

The Dots (.) are Blank Rows

I will be very gratefull to you.

Delete Rows With 2 Or More Blank Columns, Highlight If 1 Blank - Excel

View Content
Hii,

I have around 1800 records
each record has columns from A to BH
I want to delete rows(which has 2 or more blank column values for that row)
If only one blank field is there in a row, then we have to highlight it with some colour

Could you please tell me how to solve it.
I tried COUNTIF , but syntax is for a column wise

Delete Blank Rows Automatically Between Rows Of Data - Excel

View Content
I have data that is arranged down column A with the following format:
--------------------
Last Name, First Name Address City, State Zip County

There is a few spaces between the County and the next record (the amount of spaces is always different). I have the following macro to copy and transpose the data and then delete the empty spaces between the rows to get the data in a nice order:

Sub JudgmentMacro1()
Dim myAreas As Areas, myArea As Range
On Error Resume Next
Set myAreas = Columns(1).SpecialCells(2).Areas
If myAreas Is Nothing Then Exit Sub
For Each myArea In myAreas
For Each r In myArea.Resize(, 2)
If r.Value "" Then
n = n + 1
myArea(1).Offset(, n + 2).Value = r.Value
End If
Next
n = 0
Next
Columns("D:D").EntireColumn.AutoFit
Columns("E:E").EntireColumn.AutoFit
ActiveWindow.SmallScroll ToRight:=1
Columns("F:F").EntireColumn.AutoFit
Columns("G:G").EntireColumn.AutoFit
Columns("D:G").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Delete Shift:=xlUp
Columns("E:G").Select
ActiveWindow.SmallScroll ToRight:=1
Selection.Cut Destination:=Columns("F:H")
Columns("D:D").Select
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Columns("E:E").EntireColumn.AutoFit
End Sub

My problem is this: When I delete the empty rows, there are some records that have data missing: example:

Last Name, First Name
Address
County
(NOTICE: THE LINE WITH CITY, STATE, ZIP is missing). So this throws off the entire data when it is sorted with the macro above. Any way to have the macro skip over the data if its is NOT 4 rows in length??? OR, is there a way to delete rows without using the method I use above of deleting ALL blank cells. Basically, I want this data to be ready for mail merge, and if there are rows of blank cells in between, it will not be useful for mail merge with a word document. (Note: I am a macro idiot : )

Thank you in advance.

Delete 1 Blank Row If 2 Blank Rows - Excel

View Content
Good afternoon everyone.

I have a spreadsheet with data grouped, and there are 2 blank rows in between each group. How can I write a macro that would delete 1 blank row where there are 2?

Thanks for any help!

-scott

Random Tutorials
Net Present Value / Discounted Cash Flow Calculations
(Intermediate)
FV() Find the Future Value of Cash Today
         -Savings/Retirement Plan Calculations

(Intermediate)
Bond Pricing Calculations for Simple Bonds
         - Future Value, Present Value, Interest Rate, etc.

(Intermediate)
Extract Text from Cells - Intermediate Example
(Intermediate)
Remove #N/A Error Result from Empty VLOOKUP() Formulas
(Intermediate)
Introduction to Making Formulas in Excel
(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