I have 2 workbooks, Workbook 1 & Delete. In "Delete", I have column A matched with value in column D in "Workbook 1"
What I want to do is, if value in Column A "Delete" matches with Column D "WB1", macro should delete entire row in "WB1".
As well, "Workbook 1" is not constant. I want whatever in WB "Delete" I can use to delete in multiple defined workbooks.
I was able to put together a macro from googling but still doesn't work. Not sure what really went wrong...
Appreciate your help!
What I want to do is, if value in Column A "Delete" matches with Column D "WB1", macro should delete entire row in "WB1".
As well, "Workbook 1" is not constant. I want whatever in WB "Delete" I can use to delete in multiple defined workbooks.
I was able to put together a macro from googling but still doesn't work. Not sure what really went wrong...
Appreciate your help!
VBA Code:
Sub DeleteRow()
Dim WrBK1 as Workbook, WrkBK2 as Workbook, wsPlanner as Worksheet, wsDelete as Worksheet
Dim LRPlanner As Long, Cell As Range, MyRange as Range, rgMatch as Range
Set WrBK1 = Workbooks("Workbook1.xlsb")
Set WrBK2 = Workbooks("Delete.xlsb")
Set wsPlanner = WrBK1.Worksheets("Planner")
Set wsDelete = WrBK2.Worksheets("Delete")
LRPlanner = wsPlanner.Range("A" & Rows.Count).End(xlUp).Row
Set MyRange = wsPlanner.Range("A2:A" & LRPlanner)
Application.ScreenUpdating = False
For Each Cell in MyRange
Set rgMatch = wsDelete.Range("D" & Cell.Row)
If Cell.Value = rgMatch.Value Then
Cell.EntireRow.Delete
End If
Next cell
Application.ScreenUpdating = True
End Sub