
Sub find_dups()
Dim cella As Range, r As Range
ActiveWorkbook.Worksheets("Foglio1").Select
Range("b1:b6500").Interior.ColorIndex = xlNone
Call ordina_crescente
Set r = [b1:b6500]
For Each cella In r
If Trim(cella) <> "" And _
cella.Interior.ColorIndex <> 6 And _
count_occurrences(r, (cella)) > 1 Then
cella.Interior.ColorIndex = 6
End If
Next
End Sub
Private Function count_occurrences(r As Range, search As String)
Dim s As String, v As Variant, i As Integer, vect() As String
ReDim vect(1 To r.Count)
For Each v In r
i = i + 1
vect(i) = v
Next
s = Join(vect, vbNullChar) & vbNullChar
s = LCase(s)
search = LCase(search)
count_occurrences = Len(Replace(s, search & vbNullChar, _
search & vbNullChar & "*")) - Len(s)
End Function
Sub Conta_Colorate()
ActiveWorkbook.Worksheets("Foglio1").Select
Dim cella
Dim somma As Integer
somma = 0
For Each cella In Range("b1:b6500")
If cella.Interior.ColorIndex = 6 Then
somma = somma + 1
End If
Next
If somma = 0 Then
MsgBox "Non ci sono dati duplicati"
Else
MsgBox "Ho trovato " & somma / 2 & " dati duplicati."
End If
End Sub
|
option explicit
Sub find_dups()
Dim cella As Range, r As Range
Dim s As String, v As Variant, i As Integer, vect() As String
Dim search as String, conteggio as Long
ActiveWorkbook.Worksheets("Foglio1").Select
Range("b1:b6500").Interior.ColorIndex = xlNone
Call ordina_crescente
Set r = [b1:b6500]
ReDim vect(1 To r.Count)
For Each v In r
i = i + 1
vect(i) = v
Next
s = Join(vect, vbNullChar) & vbNullChar
s = LCase(s)
For Each cella In r
search = LCase(cella)
conteggio = Len(Replace(s, search & vbNullChar, _
search & vbNullChar & "*")) - Len(s)
If Trim(cella) <> "" And _
cella.Interior.ColorIndex <> 6 And _
conteggio > 1 Then
cella.Interior.ColorIndex = 6
End If
Next
End Sub
Sub Conta_Colorate()
ActiveWorkbook.Worksheets("Foglio1").Select
Dim cella
Dim somma As Integer
somma = 0
For Each cella In Range("b1:b6500")
If cella.Interior.ColorIndex = 6 Then
somma = somma + 1
End If
Next
If somma = 0 Then
MsgBox "Non ci sono dati duplicati"
Else
MsgBox "Ho trovato " & somma / 2 & " dati duplicati."
End If
End Sub |
Sub Find_Dups2()
Dim cella As Range, R As Range, NoDups As New Collection, Dups As New Collection, s As Variant
Dim Somma As Integer
ActiveWorkbook.Worksheets("Foglio8").Select
Range("b1:b6500").Interior.ColorIndex = xlNone
[b1:b6500].Sort key1:=[b1], Header:=xlNo
Set R = [b1:b6500]
On Error Resume Next
For Each cella In R
NoDups.Add Item:=cella, Key:=CStr(cella)
If Err.Number <> 0 Then
Dups.Add Item:=cella
Err.Number = 0
End If
Next
Set cella = [b1]
For Each s In Dups
Do
Set cella = R.Find(what:=s, lookat:=xlWhole)
If cella.Interior.ColorIndex = 6 Then Exit Do
Set R = Range("B" & cella.Row & ":B6500")
cella.Interior.ColorIndex = 6
Somma = Somma + 1
Loop
Next
MsgBox "Ho trovato tot " & Somma / 2 & " celle colorate"
End Sub
|
