Hi
I have a workbook (MASTER) that copies a single row of information on contact names and addresses from other workbooks (Slave1, Slave2, etc) and pastes the information into a worksheet (ALL DATA) in MASTER.
Before pasting into MASTER, I want the process to check if the contact information is already in ALLDATA / MASTER. If it is, I need the option of overwriting the existing data, (there may be a change to address or some such), whatever row it's in, or paste the information into a new line if it's a new contact and doesn't cause a duplicate.
So far I've found a process that identifies a duplicate in a single cell in a column, but then asks for you to type in new information to overwrite the information to be pasted, rather than paste over the existing information.
Private Sub Worksheet_Change(ByVal Target As Range)
'Check for duplicates in the table
Dim Msg2 As String, Ans2 As Variant
Dim FindRowNumber As Long
Dim rng As Range, r As Range, Msg1 As String, x As Range, temp, check
Set rng = Intersect(Columns(1), Target)
If Not rng Is Nothing Then
Application.EnableEvents = False
For Each r In rng
If Not IsEmpty(r.Value) Then
If Application.CountIf(Columns(1), r.Value) > 1 Then
Msg1 = Msg1 & r.Value
If x Is Nothing Then
r.Activate
Set x = r
Else
Set x = Union(x, r)
End If
End If
End If
Next
If Len(Msg1) Then
MsgBox "An Entry already exists for " & Msg1
x.Select
For Each r In x
r.Activate
Do
Msg2 = "Would you like to Overwrite the current entry for " & _
r.Value
Ans = MsgBox(Msg2, vbYesNo)
'NEED TO PASTE OVER THE CURRENT ENTRY HERE.........
temp = Application.InputBox(Msg2 & _
r.Value, "Invalid ; " & IIf(Len(temp), temp, r.Value))
check = Application.CountIf(Columns(1), temp)
Loop Until (check = 0) * (temp <> "") * (temp <> False)
r.Value = temp
temp = ""
Next
End If
Set rng = Nothing
Set x = Nothing
Application.EnableEvents = True
End If
End Sub
I've attached a mock workbook in which I copy the list on sheet 2 into column A on sheet 1 to show the above code working, but now need to expand the code to identify the row the duplicate info is in and overwrite it with the info to be pasted, or paste the incoming info as a new line at the end of the list.
Thanks in advance!!
Frankie
Bookmarks