根据用户输入在列中查找重复值

时间:2017-01-05 08:54:30

标签: excel duplicates inputbox

我正在尝试在列中找到重复的单元格。我更改了代码,手动将范围提供给用户定义。但它给了我错误。应该从下面的代码中修改什么来获取用户输入和处理。

Sub DupEntry()
Dim cel As Variant
Dim rng As Range
Dim clr As Long
Dim colname As Variant
Dim j As Long

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

colname = Application.InputBox("Input Column Name")
j = Cells(l, colname).Column
Set rng = Range(j & "1:" & j & Range(j & "1048576").End(xlUp).Row)
rng.Interior.ColorIndex = xlNone
clr = 3
For Each cel In rng
If Application.WorksheetFunction.CountIf(rng, cel) > 1 Then
If Application.WorksheetFunction.CountIf(Range(j & "1:" & j & cel.Row), cel) = 1 Then
cel.Interior.ColorIndex = clr
clr = clr + 1
Else
cel.Interior.ColorIndex = rng.Cells(WorksheetFunction.Match(cel.Value, rng, False), 1).Interior.ColorIndex
End If
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub 

这里我使用inputbox来捕获用户输入。但我最终没有出现任何错误。我得到运行时错误1004,应用程序定义错误请帮我捕获选择列的用户输入。谢谢。

0 个答案:

没有答案