防止细胞范围内的重复

时间:2016-10-05 08:24:20

标签: excel vba duplicates

我有一个宏可以防止A:H

范围内的重复

但是我不知道如何更改宏以防止输入“[name] [space] [surname]”两次以上。在一个单元格中可以有多个“[name] [space] [surname]”

 Option Explicit
 Option Compare Text


Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, cel As Range
Dim What As Variant


Set rng = ActiveSheet.UsedRange.Columns("A:H")
If Target.Value = "" Then Exit Sub
If Not Intersect(Target, rng) Is Nothing Then
What = "*" & Target.Value & "*"
For Each cel In rng.Cells
    If cel.Value Like What Then
        Target.ClearContents
        MsgBox "Text already present!"
    End If
Next cel
End If
End Sub

0 个答案:

没有答案