基于文本和符号标记单元格值

时间:2016-09-14 12:40:28

标签: excel vba excel-vba excel-2007

我在A栏中会有以下值; A1:11/5,A2:11 / 5R,A3:11/6,A4:11/7,A5:11/5 $,A6:11/5

如果数字相同而不考虑结束符号,我想在第10列中将这些单元格标记为重复:例如:A1,A2,A5,A6是重复的,应在Col J1,J2,J5和J6中标记。

以下代码仅适用于数字。它不计算单元格值的结束符号。任何修改代码以获得所需输出的建议都值得赞赏。

Sub FindDuplicates()

Dim LastRow As Long, matchFoundIndex As Long, iCntr As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row

For iCntr = 1 To LastRow             ' 1 set the start of the dup looks
    If Cells(iCntr, 1) <> "" Then
        matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), Range("A1:A" &    LastRow), 0)
        If iCntr <> matchFoundIndex Then
             Cells(iCntr, 10) = "Duplicate"
        Else
             Cells(iCntr, 10) = "E"
        End If
    End If
Next

End Sub

谢谢

1 个答案:

答案 0 :(得分:0)

假设如果不是数字,则应忽略单元格中的最后一个字符:

Sub FindDuplicates()
    Dim v As Variant
    Dim LastRow As Long, x As Long
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row

    For x = 1 To LastRow                          ' 1 set the start of the dup looks
        If Cells(x, 1) <> "" Then

            v = IIf(IsNumeric(Right(Cells(x, 1), 1)), Cells(x, 1), Left(Cells(x, 1), Len(Cells(x, 1)) - 1))
            Cells(x, "J") = IIf(Application.Match(v, Range("A1:A" & LastRow), 0) > 1, "E", "Duplicate")

        End If
    Next

End Sub

Find Duplicates