Forum Discussion
sebring1983
Jun 05, 2023Copper Contributor
Delete Rows if cell value in multiple columns matches on a different sheet
I am looking to delete rows from Sheet 3 in Multiple columns ( I think I might have to make tables for this ) if say cell data in Columns B,F,I matches cell data from sheet 4 in column B. The VBA I h...
- Jun 06, 2023
Sub deleteentries() Dim lastrow, i, j As Long Dim k As Variant For j = 2 To 30 Step 4 lastrow = Worksheets("Inventory Tracker").Cells(1048576, j).End(xlUp).Row For i = lastrow To 4 Step -1 k = Application.Match(Worksheets("Inventory Tracker").Cells(i, j).Value, Worksheets("sheet4").Columns(2), 0) If Not (IsError(k)) Then Worksheets("Inventory Tracker").Cells(i, j).Delete Worksheets("Inventory Tracker").Cells(i, j + 1).Delete Worksheets("Inventory Tracker").Cells(i, j + 2).Delete Else End If Next i Next j End SubUnfortunately i didn't correctly understand what you want to do. Now this code checks if a serial number from the Inventory Tracker is found anywhere in column B of Sheet 4. If it's found the corresponding data is deleted in sheet Inventory Tracker.
OliverScheurich
Jun 06, 2023Gold Contributor
Sub deleteentries()
Dim lastrow, i, j As Long
Dim k As Variant
For j = 2 To 30 Step 4
lastrow = Worksheets("Inventory Tracker").Cells(1048576, j).End(xlUp).Row
For i = lastrow To 4 Step -1
k = Application.Match(Worksheets("Inventory Tracker").Cells(i, j).Value, Worksheets("sheet4").Columns(2), 0)
If Not (IsError(k)) Then
Worksheets("Inventory Tracker").Cells(i, j).Delete
Worksheets("Inventory Tracker").Cells(i, j + 1).Delete
Worksheets("Inventory Tracker").Cells(i, j + 2).Delete
Else
End If
Next i
Next j
End SubUnfortunately i didn't correctly understand what you want to do. Now this code checks if a serial number from the Inventory Tracker is found anywhere in column B of Sheet 4. If it's found the corresponding data is deleted in sheet Inventory Tracker.
sebring1983
Jun 06, 2023Copper Contributor
That works!! one day I will have the time to learn how to use Macros better.