将数据复制到来自其他工作表的主工作表而不重复

我有四个工作簿,其中三个用于数据input,而另一个用于存放其他工作簿中input的所有数据。 事实上,它是一个主要的工作手册。 我需要代码来复制在工作簿1中的每个工作簿中input的数据,以将其复制到主工作簿的工作表1上的下一个可用行,但是如果要从这些工作簿复制的数据是重复的,则会popup一个消息框显示它的重复。 准确地说,我希望用户在列j中inputp指示过程,然后单击电子表格中的button将数据复制到主表。

我会很高兴的任何援助。 万分感谢您的帮助。

Public Sub CopyData() ' To use Dictionary, add Microsoft.Script.Runtime in Tools->Reference Dim dataDict As New Dictionary Dim ws As Worksheet, i As Integer, r As Long, lastR As Long, c As Long, keyString As String lastR = 2 For i = 1 To 3 Set ws = Workbooks.Open("Your file").Worksheets(1) ' Step 1. Loop through all the rows r = 2 ' Assume data starts at row 2 Do While ws.Cells(r, 1) <> "" ' Step 2. Check duplicates ' Step 2.1 Generate keys c = 1 keyString = "" Do While ws.Cells(r, c) <> "" keyString = keyString & ws.Cells(r, c) c = c + 1 Loop ' Step 2.2 Now check duplicates in dictionary If dataDict.Exist(keyString) = False Then ' Copy data here ' Increment last row in the master workbook lastR = lastR + 1 Else ' Duplicate found - Highlight or do whatever here End If r = r + 1 Loop Next i End Sub