How to find empty rows between two rows and remove those rows and leave just one empty row?

ironny90

Board Regular
Joined
Mar 29, 2022
Messages
72
Office Version
  1. 2010
Platform
  1. Windows
I know this is a simple question, but how to find the empty rows in between and remove all but one? I used a very redundant method - find the cells that are above and below the empty rows, offset 1 or 2, select the rows and delete.

Is there a way to find the first/last cell with content? I think I saw it somewhere, just not sure where:) Thank you!!!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I think it would be most beneficial to us if you show us a small sample of what your data looks like to start, and your expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
add an empty column at the RHS with a formula, autofilter that column and delete the visible rows
VBA Code:
Sub One_Empty_Row()
     With ActiveSheet
          Set c = .UsedRange
          With c.Resize(, 1).Offset(, c.Columns.Count)
               .Offset(1).Resize(.Rows.Count - 1).FormulaR1C1 = "=IF(COUNTA(RC1:RC[-1])=0,sum(R[-1]C,1),0)"
               .Cells(1, 1).Value = "header"
               .AutoFilter 1, ">1"
               .Offset(1).SpecialCells(xlVisible).EntireRow.Delete
               .AutoFilter
               .Resize(.Rows.Count + 1).ClearContents
          End With
     End With
End Sub
 
Upvote 0
add an empty column at the RHS with a formula, autofilter that column and delete the visible rows
VBA Code:
Sub One_Empty_Row()
     With ActiveSheet
          Set c = .UsedRange
          With c.Resize(, 1).Offset(, c.Columns.Count)
               .Offset(1).Resize(.Rows.Count - 1).FormulaR1C1 = "=IF(COUNTA(RC1:RC[-1])=0,sum(R[-1]C,1),0)"
               .Cells(1, 1).Value = "header"
               .AutoFilter 1, ">1"
               .Offset(1).SpecialCells(xlVisible).EntireRow.Delete
               .AutoFilter
               .Resize(.Rows.Count + 1).ClearContents
          End With
     End With
End Sub
Thank you! this is a good way! nice code.
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,217
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top