b_bookg.gif (182 bytes)Guides (MS-Excel97)

Macro - Deleting empty rows

M-1

Demonstrates: Macros
l_stone.gif (2795 bytes)

1. If row order doesn't matter
a. Highlight all data
b. Sort the rows
Empty rows will be sorted together, so delete

b_ref.gif (1385 bytes)Ref: Walkenbach, J. (1997, Nov)

 

Sub DeleteEmptyRows()
  LastRow=ActiveSheet.UsedRange.Rows.Count
  Application.ScreenUpdating = False
  For r = LastRow To 1 Step -1
    If Application.CountA(Rows(r)) = 0 Then
    Rows(r).Delete
  Next r
End Sub

If row order matters, create a macro that deletes from the last row to the first.
  • Select Tools | Macro | VB Editor, then Insert | Module
  • Type in the macro (left)
  • To Run choose Tools | Macro | Macros and select DeleteEmptyRows
  • (NB. ScreenUpdating is switched off to spped up the macro.)
  • b_ref.gif (1385 bytes)Ref: Walkenbach, J. (1997, Nov)

[Rev 6/10/98] 6/10/98 © 1998 V/2-Com (Verhaart), P O Box 8415, Havelock North, New Zealand.