2016-07-25 92 views
0

我想从Excel表中删除重复项,我有一块代码,删除重复没有任何问题,我想知道如果我可以让它提示消息框当发现一个副本沿着“这个条目是一个重复的条目”说什么的时候有什么建议?这是我到目前为止:Excel vba MsgBox显示重复时发现消息

Sub AccessTransfer() 
    Range("A1:F1").Select 
    Selection.Copy 
    Sheets("Sheet2").Select 

    ActiveSheet.Paste 
    ActiveCell.Offset(0, 6).Value = "Oven" 

    Range("A65536").End(xlUp).Offset(1, 0).Select 
    Call GoDupe 
    Sheets("Sheet1").Select 

    Application.CutCopyMode = False 

End Sub 



Sub GoDupe() 

    Cells.RemoveDuplicates Columns:=Array(1), Header:=xlNo 
    Range("A65536").End(xlUp).Offset(1, 0).Select 
End Sub 
+3

你会需要循环识别受骗者,并将其写入字符串。使用你所拥有的东西,没有办法确定哪些实际上是伪造的,哪些是独特的。 – Kyle

回答

1

而不是通过循环,识别和提示每个副本,你可以简单地突出显示所有副本,并提示用户一次。 你GoDupe()子可能是这个样子:

Sub GoDupe() 

Cells.FormatConditions.AddUniqueValues 
With Cells.FormatConditions(Cells.FormatConditions.Count) 
    .DupeUnique = xlDuplicate 
    .Interior.Color = RGB(255, 0, 0) 
End With 
If MsgBox("Red highlighted cells are duplicated. OK to remove duplicates?", vbOKCancel) = vbOK Then 
    Cells.RemoveDuplicates Columns:=Array(1), Header:=xlNo 
    Range("A65536").End(xlUp).Offset(1, 0).Select 
End If 
Cells.FormatConditions(Cells.FormatConditions.Count).Delete 

末次

+0

只有一件事,我只想要突出显示第一列(A列)并删除重复项,其他所有列有时会有重复值,这没关系,是否有这样的功能? –

+0

然后,您应该从特定的范围调用'RemoveDuplicates'函数,而不是简单的'Cells'。例如。 'Range(“$ A:$ A”)。RemoveDuplicates Columns:= Array(1),Header:= xlNo' – hughg