Results 1 to 10 of 10

speedup the code for deleting rows

Threaded View

  1. #1
    Registered User
    Join Date
    01-05-2012
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    22

    speedup the code for deleting rows

    Hi,
    I have this code which is supposed to delete rows containing "0" and "null" in all worksheets.
    But this is taking too much time and seems like system is gonna hang.

    Is there anything we can do to speed up code. Also, its "search all worksheet" function is not working, and is doing work in just the active worksheet.
    Please help.

    Sub WorksheetLoop()
    
        Dim I As Long
        Dim sh As Worksheet
        Dim LastRow As Long
        
            With Application
                .ScreenUpdating = False
                .EnableEvents = False
            End With
    
           'Begin the loop.
            For Each sh In ActiveWorkbook.Worksheets
            
              LastRow = sh.Cells(Rows.Count, "D").End(xlUp).Row
            
               For I = LastRow To 1 Step -1
                 If (Cells(I, "D").Value) = "0" Then
                     Cells(I, "D").EntireRow.Delete
                 End If
              Next I
                
           
    
               For I = LastRow To 1 Step -1
                 If (Cells(I, "D").Value) = "" Then
                     Cells(I, "D").EntireRow.Delete
                 End If
              Next I
                
            Next sh
    
            With Application
                .ScreenUpdating = True
                .EnableEvents = True
            End With
    
    End Sub
    Last edited by maheshwow; 01-17-2012 at 02:46 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