csebring1983
New Member
- Joined
- May 15, 2023
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
I am looking to delete rows from Sheet 3 in Multiple columns ( I think I might have to make tables for this ) if cell data in Columns B,F,I matches cell data from sheet 4 in column B. The VBA I have for a different sheet works but only to match 1 column as it only looks to column B on both sheets.
Sub delete_selected_rows()
Dim rng1 As Range, rng2 As Range, rngToDel As Range, c As Range
Dim lastRow As Long
With Worksheets("Sheet3")
lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
Set rng1 = .Range("B4:B" & lastRow)
End With
Set rng2 = Worksheets("Sheet4").Range("B:B")
For Each c In rng1
If Not IsError(Application.Match(c.Value, rng2, 0)) Then
'if value from rng1 is found in rng2 then remember this cell for deleting
If rngToDel Is Nothing Then
Set rngToDel = c
Else
Set rngToDel = Union(rngToDel, c)
End If
End If
Next c
If Not rngToDel Is Nothing Then rngToDel.EntireRow.Delete
End Sub
Sub delete_selected_rows()
Dim rng1 As Range, rng2 As Range, rngToDel As Range, c As Range
Dim lastRow As Long
With Worksheets("Sheet3")
lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
Set rng1 = .Range("B4:B" & lastRow)
End With
Set rng2 = Worksheets("Sheet4").Range("B:B")
For Each c In rng1
If Not IsError(Application.Match(c.Value, rng2, 0)) Then
'if value from rng1 is found in rng2 then remember this cell for deleting
If rngToDel Is Nothing Then
Set rngToDel = c
Else
Set rngToDel = Union(rngToDel, c)
End If
End If
Next c
If Not rngToDel Is Nothing Then rngToDel.EntireRow.Delete
End Sub