VBA to delete rows if value matched across workbooks

kbui92

New Member
Joined
Mar 4, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
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!

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
 
Save a copy of the Gala sheet using the name "Lady Smith" (xlsb file). Change wbArr to include only the two sheets:
VBA Code:
wbArr = Array("Gala.xlsb", "Lady Smith.xlsb")
Try the macro again.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Save a copy of the Gala sheet using the name "Lady Smith" (xlsb file). Change wbArr to include only the two sheets:
VBA Code:
wbArr = Array("Gala.xlsb", "Lady Smith.xlsb")
Try the macro again.
I don't know what happened but IT'S WORKING NOW!!! I didn't even change anything...

Thank you very much for your help!!!!!!

1646690995834.png
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,709
Members
449,331
Latest member
smckenzie2016

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top