Help changing code

dee101

Active Member
Joined
Aug 21, 2004
Messages
282
I found this code to check for duplicates in column F, works fine if all the data is numbers, how can I change it to work if the data is numbers and letters?
Thought I could just remove the IsNumeric part but I can't make it work, this is being used in Excel 2003.
Thanks



Code:
Sub CheckForDuplicates()
    Dim dict As Object
    Dim LR As Long, i As Long, v As Variant, strResult As String

    Set dict = CreateObject("Scripting.Dictionary")

    With ActiveSheet
        LR = .Range("F" & .Rows.Count).End(xlUp).Row
        For i = 2 To LR
            If IsNumeric(Range("F" & i).Value) And WorksheetFunction.CountIf(Columns("F"), Range("F" & i).Value) > 1 Then

                If dict.Exists(.Range("F" & i).Value) Then
                    dict.Item(.Range("F" & i).Value) = dict.Item(.Range("F" & i).Value) & .Range("F" & i).Row & " / "
                Else
                    dict.Add .Range("F" & i).Value, .Range("F" & i).Row & " / "
                End If
            End If
        Next i
    End With

    For Each v In dict.keys
        strResult = strResult & "Duplicates: " & v & vbNewLine & "In Rows: " & _
                    Left(dict.Item(v), Len(dict.Item(v)) - 1) & vbNewLine & vbNewLine
    Next v

    If strResult = "" Then
        'MsgBox "No duplicates"
    Else
        MsgBox strResult, , "Duplicates"

    End If

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi. Have you tried like this:
Code:
If WorksheetFunction.CountIf(Columns("F"), Range("F" & i).Value) > 1 Then
 
Upvote 0
Give this macro a try in place of the one you posted...
Code:
[table="width: 500"]
[tr]
	[td]Sub CheckForDuplicates()
  Dim X As Long, Data As Variant
  Data = Range("F2", Cells(Rows.Count, "F").End(xlUp))
  With CreateObject("Scripting.Dictionary")
    For X = 1 To UBound(Data)
      If Len(.Item(Data(X, 1))) = 0 Then
        .Item(Data(X, 1)) = vbLf & vbLf & "Duplicates: " & Data(X, 1) & vbLf & "In Rows: " & X
      Else
        .Item(Data(X, 1)) = .Item(Data(X, 1)) & " / " & X
      End If
    Next
    For X = 1 To UBound(Data)
      If Not .Item(Data(X, 1)) Like "* / *" Then .Remove Data(X, 1)
    Next
    MsgBox Mid(Join(.items), 3)
  End With
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top