+ Reply to Thread
Results 1 to 3 of 3

Exclude rows from loop

Hybrid View

inky Exclude rows from loop 06-10-2008, 09:53 PM
Leith Ross Hello inky, Set FirstRow =... 06-10-2008, 10:23 PM
inky thanks Leith 06-11-2008, 06:34 AM
  1. #1
    Forum Contributor
    Join Date
    09-19-2007
    Posts
    115

    Exclude rows from loop

    hello

    i would like the following code to loop from row 22 down.

    Sub Delete_Row()
        Dim Firstrow As Long
        Dim Lastrow As Long
        Dim Lrow As Long
        Dim CalcMode As Long
        Dim ViewMode As Long
    
        With Application
            CalcMode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
    
        'We use the ActiveSheet but you can replace this with
        'Sheets("MySheet")if you want
        With ActiveSheet
    
            'We select the sheet so we can change the window view
            .Select
    
            'If you are in Page Break Preview Or Page Layout view go
            'back to normal view, we do this for speed
            ViewMode = ActiveWindow.View
            ActiveWindow.View = xlNormalView
    
            'Turn off Page Breaks, we do this for speed
            .DisplayPageBreaks = False
    
            'Set the first and last row to loop through
            Firstrow = .UsedRange.Cells(1).Row
            Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
    
            'We loop from Lastrow to Firstrow (bottom to top)
            For Lrow = Lastrow To Firstrow Step -1
    
                'We check the values in the A column in this example
                With .Cells(Lrow, "H")
    
                    If Not IsError(.Value) Then
    
                        If .Value = "0" Then .EntireRow.Delete
                        'This will delete each row with the Amount "0"
                        
                    End If
    
                End With
    
            Next Lrow
    
        End With
    
        ActiveWindow.View = ViewMode
        With Application
            .ScreenUpdating = True
            .Calculation = CalcMode
        End With
    
    End Sub
    how do i change
    Firstrow = .UsedRange.Cells(1).Row
    to Row 22? is this all that is required?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello inky,

    Set FirstRow = 22

    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    09-19-2007
    Posts
    115
    thanks Leith

+ Reply to Thread

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