excel不允许重复数据的vba代码

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngA As Range
Dim cntA As Integer
For Each rngA In Target
If rngA = “” Then
Else
cntA = Application.WorksheetFunction.CountIf(ActiveSheet.Range(“A:A”), rngA)’查找的列范围
If cntA > 1 Then
MsgBox “重复数据[” & rngA & “]”, vbCritical, “错误”
rngA=””
End If
End If
Next
End Sub



发表评论

电子邮件地址不会被公开。 必填项已用*标注

+ 1 = 5