Detecting duplicates formatted as text

前端 未结 5 540
春和景丽
春和景丽 2020-12-21 23:08

I need a function to detect duplicates formatted as text.

This cannot distinguish between \"46.500\" and\"46.5000\". CountIf probably compares cells as numbers. Thes

5条回答
  •  [愿得一人]
    2020-12-21 23:39

    Assuming all the "text" cells are textual representations of numbers, then the following change will work:

    Function check_duplicates(column As String)
        Dim lastrow As Long
        Dim x As Long
    
        lastrow = Range(column & "65536").End(xlUp).Row
        For x = lastrow To 1 Step -1
    
            If Application.WorksheetFunction.CountIf(Range(column & "1:" & column & lastrow), Val(Range(column & x).Text)) > 1 Then
                check_duplicates = x  ' return row with a duplicate
                x = 1
            Else
             check_duplicates = 0
            End If
        Next x
    End Function
    

    It coerces the value of the criteria cell to a value by the use of the Val function

提交回复
热议问题