Instead of Countif()
you can use Worksheet.Evaluate
to run an array formula which will not count the cells as though they're numbers:
Dim dupes As Long, c As Range, ws As Worksheet, col As Long, rng As Range, n
Set ws = ActiveSheet 'or whatever
col = ActiveCell.Column
Set rng = ws.Range(ws.Cells(1, col), ws.Cells(Rows.Count, col).End(xlUp))
For Each c In rng.Cells
'this will not count values as numbers...
n = ws.Evaluate("=SUM(1*(" & rng.Address & "=" & c.Address & "))")
If n > 1 Then
dupes = dupes + 1
c.Interior.ThemeColor = xlThemeColorAccent5
Else
c.Interior.ColorIndex = xlNone
End If
Next
Workbooks("PERSONAL.xlsb").Sheets("History").Range("F2").Value = _
IIf(dupes > 0, "Duplicates", "No Duplicates")
If dupes > 0 Then MsgBox "Duplicate Sheet Names Found"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…