Removal of blank rows

BambiLou

New Member
Joined
Dec 2, 2010
Messages
11
Without sorting and leaving data as it is received, how do I remove blank rows from workbook

Many thanks
Bambi:)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hello BambiLou,

This macro will remove all empty rows on the active sheet and shift the rows so there are no breaks in the data. If you are using Excel 2007 or later then there are better ways to remove the blank rows.
Code:
Sub RemoveBlankRows()

  Dim LastRow As Long
  Dim R As Long
  
    LastRow = ActiveSheet.UsedRange.Rows.Count - ActiveSheet.UsedRange.Row + 1
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
      For R = LastRow To ActiveSheet.UsedRange.Row Step -1
        If WorksheetFunction.CountA(ActiveSheet.Rows(R).EntireRow) > 0 Then
           ActiveSheet.Rows(R).EntireRow.Delete
        End If
      Next R
  
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdaing = True
    
End Sub
Adding the Macro

  1. Copy the macro above pressing the keys CTRL+C
  2. Open your workbook
  3. Press the keys ALT+F11 to open the Visual Basic Editor
  4. Press the keys ALT+I to activate the Insert menu
  5. Press M to insert a Standard Module
  6. Paste the code by pressing the keys CTRL+V

    [*] Make any custom changes to the macro if needed at this time.
  7. Save the Macro by pressing the keys CTRL+S
  8. Press the keys ALT+Q to exit the Editor, and return to Excel.


To Run the Macro...
To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Sincerely,
Leith Ross
 
Upvote 0
Where are the blanks rows? In one column?

If in one column you could use...

Code:
Sub DelBlks()
    Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
This would remove rows from blanks in column A
 
Upvote 0
Have just tried this macro and unfortunately, there is an error in this section ... would you be able to advise please

Application.ScreenUpdaing = True
Many thanks
Bambi
 
Upvote 0
Hello Bambiloou,

Sorry, a word is misspelled. It should read Application.ScreenUpdating= True

Sincerely,
Leith Ross
 
Upvote 0
Thanks Leith ... only it removes all the data and leaves the blank

I did just copy and paste like you said
Must be doing something wrong ... can you help please
 
Upvote 0
Hello BambiLou,

I need more sleep. Found another error. I have tested this version and it works.
Code:
Sub RemoveBlankRows()

  Dim LastRow As Long
  Dim R As Long
  
    LastRow = ActiveSheet.UsedRange.Rows.Count - ActiveSheet.UsedRange.Row + 1
    
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    
      For R = LastRow To ActiveSheet.UsedRange.Row Step -1
        If WorksheetFunction.CountA(ActiveSheet.Rows(R).EntireRow) = 0 Then
           X = WorksheetFunction.CountA(ActiveSheet.Rows(R).EntireRow)
           ActiveSheet.Rows(R).EntireRow.Delete
        End If
      Next R
  
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Hello BambiLou,

Glad it is working. Hope you didn't lose any important data due to my errors.

Sincerely,
Leith Ross
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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