Thread: [Solved] count and delete row
View Single Post
 
Old 09-29-2016, 12:17 PM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

I believe this does what you're asking, although it doesn't match your after file.
Code:
Sub tomlam()
' remove rows with blank "C" and limit to 15

    Dim lr As Long
    Dim r As Long
    Dim i As Integer

With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With

'delete rows where C is blank
Range("C1", Cells(Rows.Count, "C").End(xlUp)).SpecialCells(xlBlanks).EntireRow.Delete

'limit to 15
lr = Cells(Rows.Count, "C").End(xlUp).Row
For r = lr To 2 Step -1
    If Cells(r, "C").Value = "total export" Then
        i = 0
    Else
        i = i + 1
    End If
    If i > 15 Then Rows(r).Delete
Next r

With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With

End Sub
Reply With Quote