在excel中用VBA写代码,怎样判断某一指定列内容是否重复??

发布网友

我来回答

3个回答

热心网友

Sub s()
    Set d = CreateObject("scripting.dictionary")
    c = InputBox("请输入列标:")
    n = Cells(Rows.Count, c).End(3).Row
    For i = 1 To n
        a = Cells(i, c).Text
        If a <> "" Then
            If d.exists(a) Then
                MsgBox c & "列内容有重复!"
                Exit Sub
            Else
                d.Add a, ""
            End If
        End If
    Next
    MsgBox c & "列内容无重复!"
End Sub

热心网友

1、定义一个数组,如strName()
2、检索A列,把所有不同的名称存入数组strName中,此数组中包含全部名称,且每个名称只有一个,不重复的。
3、按顺序读取数组中的名称,再检索A列,统计结果,存入B列。

热心网友

Sub test()
Dim r As Long
Dim tempC, tempC1 As Range

r = [A65536].End(xlUp).Row

For Each tempC In Range("A2:A" & r)
tempC.Offset(0, 2).Value = Application.WorksheetFunction.CountIf(Range("A2:A" & r), tempC.Value)

If tempC.Row >= 3 Then
Set tempC1 = Range("A2:A" & (tempC.Row - 1)).Find(tempC.Value, LookIn:=xlValues)
If Not tempC1 Is Nothing Then
tempC1.Offset(0, 1) = tempC1.Offset(0, 1) + tempC.Offset(0, 1)
Rows(tempC.Row).Hidden = True
End If
End If
Next
End Sub

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com