Skip to content

Instantly share code, notes, and snippets.

@danwagnerco
Last active January 22, 2016 13:00
Embed
What would you like to do?
This script deletes rows that match "Invoice.zip" or "Thumbs.db"
Option Explicit
Public Sub DeleteRowsWithForLoop()
Dim wksData As Worksheet
Dim lngLastRow As Long, lngIdx As Long
'Set references up-front
Set wksData = ThisWorkbook.Worksheets("data")
With wksData
'Identify the last row
lngLastRow = .Range("F" & .Rows.Count).End(xlUp).Row
'Loop from the BOTTOM to the top, deleting rows as you go
For lngIdx = lngLastRow To 6 Step -1
If .Cells(lngIdx, 6) = "Invoice.zip" Or _
.Cells(lngIdx, 6) = "Thumbs.db" Then
.Rows(lngIdx).Delete
End If
Next lngIdx
End With
'Let the user know the script has finished
MsgBox "Boom! Rows deleted."
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment