Skip to content

Instantly share code, notes, and snippets.

@elyse0
Created June 1, 2022 05:02
Show Gist options
  • Save elyse0/67530228636d3c1a521dba3310dd9671 to your computer and use it in GitHub Desktop.
Save elyse0/67530228636d3c1a521dba3310dd9671 to your computer and use it in GitHub Desktop.
Delete excel rows in selected range that match a specific column value
Sub DeleteRowsOnSelectedRangeThatMatch()
Application.ScreenUpdating = False
Dim SelectedRange As Range
Set SelectedRange = Selection
RowCount = SelectedRange.Rows.Count
FirstRowIndex = CInt(Split(SelectedRange.Cells(1).Address, "$")(2))
LastRowIndex = FirstRowIndex + (RowCount - 1)
' Change these values
FilterColumn = "B"
SearchValue = ""
For i = LastRowIndex To FirstRowIndex Step -1
If Cells(i, FilterColumn).Value = SearchValue Then
Rows(i).Delete
' MsgBox Cells(i, FilterColumn).Value
End If
Next i
Application.ScreenUpdating = True
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment