VBA code to check for and delete duplicate entries, then copy and paste data across sheets, with timestamp, triggered by drop down

handoverhammer

New Member
Joined
Mar 30, 2018
Messages
24
First and foremost, you guys rock!

Last week I learned how to copy and paste data based on drop downs. Thanks Fluff. Over the weekend, I added timestamps and message boxes.

Now, I'm wondering, can we first check for and remove any duplicate/previous entries, excluding the source, then copy and paste?

As it stands, the drop downs are in sheet1 and then depending on the selection (two, three, etc), it pushes to the corresponding sheet and creates a new entry on said sheet.

If I change the drop down on sheet1 and something has already been copied to another sheet, I want the new selection to first delete other instances of the data, excluding the original data on sheet1, then copy to the new selected sheet.

Here's what we have right now:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Target.Column = 1 Then Exit Sub
If Target.Value = ("Two") Then
Dim Response As VbMsgBoxResult
Response = MsgBox("Add to Sheet2?", vbQuestion + vbYesNo)
If Response = vbNo Then Exit Sub
End If
If Target.Value = "Two" Then
With Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp)
Intersect(Target.EntireRow, Range("B:F")).Copy .Offset(1)
.Offset(1, 5) = Now
Sheets("Sheet2").Select
End With
End If
If Target.CountLarge > 1 Then Exit Sub
If Not Target.Column = 1 Then Exit Sub
If Target.Value = ("Three") Then
Response = MsgBox("Add to Sheet3?", vbQuestion + vbYesNo)
If Response = vbNo Then Exit Sub
End If
If Target.Value = "Three" Then
With Sheets("Three").Range("A" & Rows.Count).End(xlUp)
Intersect(Target.EntireRow, Range("B:F")).Copy .Offset(1)
.Offset(1, 5) = Now
Sheets("Sheet3").Select
End With
End If
End Sub

Thoughts?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Oops. When I anonymized the sheet and tab names, I made a reference error.
Code:
[COLOR=#333333]If Target.Value = "Three" Then
[/COLOR][COLOR=#333333]With Sheets("Three").Range("A" & Rows.Count).End(xlUp)[/COLOR]
should read
Code:
[COLOR=#333333]If Target.Value = "Three" Then
[/COLOR][COLOR=#333333]With Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp)[/COLOR]
[h=3][/h]
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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