Results 1 to 7 of 7

deleting empty rows

Threaded View

  1. #1
    Registered User
    Join Date
    09-14-2009
    Location
    Prague
    MS-Off Ver
    Excel 2007
    Posts
    16

    deleting empty rows

    Hi,

    I need to write a macro which checks cells in one column and if the cell is empty it deletes the whole row (which contains the cell).

    I tried this code but it doesn't delete all rows with empty cells:

    Public Sub deleterows()
    For o = 7 To 25
         If Worksheets("sheet").Cells(o, 4) = "" Then
            Rows(o).Delete
            End If
         End If
    Next o
    End Sub
    So I modified the code:

    Public Sub deleterows()
    For o = 7 To 25
         If Worksheets("sheet").Cells(o, 4) = "" Then
            Rows(o).Delete
             o = o - 1
             a = a + 1
             If a = 20 Then
                 o = 25
             End If
         End If
    Next o
    End Sub
    It works correct but it is not a proper solution (it ends the for loop after 20 deleted cells)...

    Do you have any better suggestions?

    Thanks!
    Last edited by kaipan; 09-27-2009 at 04:29 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1