Delete data if it exists elsewhere on the sheet

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
303
Office Version
  1. 365
Platform
  1. Windows
Hello,

I hope I can explain this properly.

I have new data that gets pasted into columns A-E.

I have static data (also five columns) in columns H-L.

When the new data is processed, it gets copied by a macro to the bottom of the range H-L.

What I'd like to do is, before I process anything, delete anything from A-E that already exists in H-L (because the fact that it's in H-L means I've processed it previously).

Somebody on here very kindly provided this previously which works if column A exists in column B
VBA Code:
For r = lRow1 To 1 Step -1
    If Application.WorksheetFunction.CountIf(Range("B:B"), Cells(r, "A")) > 0 Then
        Cells(r, "A").Delete Shift:=xlUp
    End If
Next r

but I need this expanded to delete five columns, not one.

Any help greatly appreciated as always.

EDIT: column C or column E will always be unique - does that make it easier, just searching for one of those values?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try
VBA Code:
For r = lRow1 To 1 Step -1
    If Application.WorksheetFunction.CountIf(Range("B:B"), Cells(r, "A")) > 0 Then
        Range(Cells(r, "A"), Cells(r, "E")).delete Shift:=xlUp
    End If
Next r
 
Upvote 0
Solution
Try
VBA Code:
For r = lRow1 To 1 Step -1
    If Application.WorksheetFunction.CountIf(Range("B:B"), Cells(r, "A")) > 0 Then
        Range(Cells(r, "A"), Cells(r, "E")).delete Shift:=xlUp
    End If
Next r
Many thanks :)

I can amend that ever so slightly to work for me, much appreciated!
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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