比如在SHEET1中的A列里有 1,2,3等数据
SHEET2中的A列里有 4,5,6等数据
于是我在SHEET3、SHEET4....中的A列输入1,2,3,4,5,6等数据时会有提示重复
也就是说,整个工作簿内任何一个A列的数据都不会重复
修改没有关系
追答Option Explicit
Dim Dic As Object, SelValue
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set Dic = Nothing
End Sub
Private Sub Workbook_Open()
Dim i%, j%
Set Dic = CreateObject("Scripting.Dictionary")
For i = 1 To Sheets.Count
For j = 1 To Sheets(i).Cells(65536, 1).End(xlUp).Row()
Dic(Sheets(i).Cells(j, 1).Value) = ""
Next j
Next i
Application.EnableEvents = True
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim WshShell As Object
Set WshShell = CreateObject("Wscript.Shell")
If Target.Column 1 Then Exit Sub
Application.EnableEvents = False
If Dic.exists(Target.Value) Then
Target = ""
WshShell.popup "重复数据!", 0.6, "提示", 64
Else
Dic.Remove (SelValue)
Dic(Target.Value) = ""
Dic("") = ""
End If
Application.EnableEvents = True
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
SelValue = Target.Value
End Sub