MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2004, 08:54 AM   #1
Imthiaz
 
Join Date: Feb 2004
Posts: 18
Default delete empty rows

Can someone help with VBA/macro to delete empty rows in a range (ie., if all the cells in a row is empty)
Imthiaz is offline   Reply With Quote
Old Mar 30th, 2004, 02:19 PM   #2
Jorgen
 
Join Date: Mar 2004
Posts: 54
Default Re: delete empty rows

Hi,
Here is an old vba-macro that pops a question and asks how many cells besides the single column selected the macro should check.

Then it runs, and shows progress in the status line.

Code:
Sub DeleteEmptyRow()       '97-10-29 Jörgen Möller
' Takes a single-column-selection row by row from the top, and checks
' if the selected cell and adjoining cells are empty

Dim Ruta3 As Object, AntRut As Integer, i As Integer, Tomma As Integer
Dim AntRader As Integer, Startrad As Integer
Dim KlarProc As Single
Dim StartTid As Date, Kvartid As Date

    If MsgBox("Do you really want to erase all empty rows (Checks selected cell& x adjoining to the right)? ", _
               vbYesNo, "Delete Empty Rows") <> vbYes Then Exit Sub
    If Selection.Columns.Count > 1 Then MsgBox "You have selected more than one column, doesn't work": Exit Sub
    AntRut = Val(InputBox("Number of cells to the right (and including) selected cell to check for emptiness?", "Cells to Check", 5))
    Application.Calculation = xlManual
    Application.ScreenUpdating = False
    Startrad = Selection.Row()
    StartTid = Now()
    AntRader = Selection.Rows.Count
      For Each Ruta3 In Selection()
        KlarProc = (Ruta3.Row - Startrad) / AntRader
        If Ruta3.Row Mod 100 = 0 Then Kvartid = StartTid - Now() + (Now() - StartTid) / KlarProc
        Application.StatusBar = "Finished with: " & Int(100 * KlarProc) & " percent. Estimated finish in: " & Kvartid

       Tomma = 0
       For i = 0 To AntRut - 1
         If IsEmpty(Ruta3.Offset(0, i)) Then Tomma = Tomma + 1
       Next i
       If Tomma = AntRut Then Ruta3.EntireRow.Delete
      Next
    Application.Calculation = xlAutomatic
    Application.StatusBar = False
    Beep
End Sub
Good luck,
Jörgen
Jorgen is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 04:33 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.