2016-09-14 48 views
0

我在列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 

谢谢

+0

什么的Excel版本? – user2676140

+0

@user,它是2007 – Kuma

回答

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

+0

我使用2007年,代码仅适用于前两个单元格(A1。A2),是否有任何要更改的内容? – Kuma

+0

我也在使用2007.列的格式是文本吗?如果您提供下载链接,我会为您工作。 – 2016-09-14 19:41:21

+0

嗨,它是文本格式。我如何添加文件? – Kuma

相关问题