Find Duplicate Values and then Clear Contents

iHuman

New Member
Joined
Aug 21, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello!

I have some VBA code to find duplicate values between two sheets (Sheet1 and Sheet2)

Sub t()
Dim c As Range, fn As Range, adr As String
With Sheets("sheet1")
For Each c In .Range("A2", .Cells(Rows.Count, 1).End(xlUp))
Set fn = Sheets("sheet2").Range("A:A").Find(c.Value, , xlValues, xlWhole)
If Not fn Is Nothing Then
adr = fn.Address
c.Interior.Color = RGB(400, 200, 100)
Do
fn.Interior.Color = RGB(400, 200, 100)
Set fn = Sheets("Sheet2").Range("A:A").FindNext(fn)
Loop While fn.Address <> adr
End If
Next
End With
End Sub


But I need it to clear the duplicate contents from Sheet 1, after it finds them.
Ideally, I'd like a message to appear first before removal.

The process would be
1. Check for duplicate values between two sheets
2. Highlight duplicate values
3. Message stating "Duplicates found, would you like to remove?"
4. If selecting yes, then removing the duplicates from Sheet 1
5. If selecting no, then keeping the duplicates highlighted.


Thanks in advance!!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hello!

I have some VBA code to find duplicate values between two sheets (Sheet1 and Sheet2)

Sub t()
Dim c As Range, fn As Range, adr As String
With Sheets("sheet1")
For Each c In .Range("A2", .Cells(Rows.Count, 1).End(xlUp))
Set fn = Sheets("sheet2").Range("A:A").Find(c.Value, , xlValues, xlWhole)
If Not fn Is Nothing Then
adr = fn.Address
c.Interior.Color = RGB(400, 200, 100)
Do
fn.Interior.Color = RGB(400, 200, 100)
Set fn = Sheets("Sheet2").Range("A:A").FindNext(fn)
Loop While fn.Address <> adr
End If
Next
End With
End Sub


But I need it to clear the duplicate contents from Sheet 1, after it finds them.
Ideally, I'd like a message to appear first before removal.

The process would be
1. Check for duplicate values between two sheets
2. Highlight duplicate values
3. Message stating "Duplicates found, would you like to remove?"
4. If selecting yes, then removing the duplicates from Sheet 1
5. If selecting no, then keeping the duplicates highlighted.


Thanks in advance!!

***OR*** another option is :
1. Find duplicate values between two sheets
2. Highlight duplicate values

Separate macro to removed highlight duplicates from Sheet 1
 
Upvote 0
***OR*** another option is :
1. Find duplicate values between two sheets
2. Highlight duplicate values

Separate macro to removed highlight duplicates from Sheet 1

Typo
*to remove highlighted duplicates from Sheet 1

Oddly there doesn't seem to be an edit post button on this site :/
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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