Created
June 1, 2022 05:02
-
-
Save elyse0/67530228636d3c1a521dba3310dd9671 to your computer and use it in GitHub Desktop.
Delete excel rows in selected range that match a specific column value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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