Dim tr, tc
tr = Target.Row
tc = Target.Column
If tr >= 1 And tc = 2 Then
x = tr Mod 2
y = WorksheetFunction.CountIf(Range("b:b"), Cells(tr - 1, 2))
Z = WorksheetFunction.CountIf(Range("b:b"), Cells(tr, 2))
If x = 0 And y >= 2 And Z >= 2 Then
Cells(tr, 2) = ""
Cells(tr - 1, 2) = ""
MsgBox "输入的数据重复,被清除"
End If
End If
End Sub
试下
Sub 重复判断()Dim i, j, k, n As Integer
Dim t, t1
i = 1
n = 1
Do While Cells(i, 3) <>"" '如果单元格,不为空,进入循环,注意C列不能右空单元格
t = Cells(i, 3) '取出C列单元格
j = Sheet1.Range("a65536").End(xlUp).Row '取出A最大非空单元格
For k = 1 To j'取出A列单元格,比例C列单元格数据,是否等于A列单元格
t1 = Cells(k, 1)
If t = t1 Then
Cells(n, 2) = t1 '如果重复,则对B列单元格赋值
End If
Next
If Cells(n, 2) = "" Then '上面只是判断是否重复,并输入了重复单元格,不重复,单元格就是空的
Cells(n, 2) = "不重复"
End If
n = n + 1
i = i + 1
Loop
End Sub
小白乱写的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)