1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Sub test()
NewFeulle_sur_doublons_test "A"
couleur_sur_doublons_test "A", 8
End Sub
Sub couleur_sur_doublons_test(ByVal col As String, coul As Integer)
Dim cn As Object, Adresse As String: Set cn = CreateObject("Adodb.connection")
Dim rs As Object
Dim a As Variant
Dim wbk_creation As Workbook
Set wbk_creation = ActiveWorkbook
Adresse = Replace(Range(Cells(1, col), Cells(Rows.Count, col).End(xlUp)).Address, "$", "")
If Not CBool(InStr(Adresse, ":")) Then Exit Sub
wbk_creation.Sheets("Feuil1").Select
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & wbk_creation.FullName & ";Extended Properties=""Excel 12.0;HDR=no;"""
Set rs = cn.Execute("Select count([F1]),[F1] from [Feuil1$" & Adresse & "] where [F1] is not null group by [F1] having count([F1])>1")
For Each a In Range(Cells(1, col), Cells(Rows.Count, col).End(xlUp))
If CStr(a.value) <> "" Then
rs.Filter = "[F1]='" & Replace(a.value, "'", "''") & "'"
If Not rs.EOF Then a.Interior.ColorIndex = coul
End If
Next
rs.Close
cn.Close
End Sub
Sub NewFeulle_sur_doublons_test(ByVal col As String)
Dim Adresse As String: Adresse = Replace(Range(Cells(1, col), Cells(Rows.Count, col).End(xlUp)).Address, "$", "")
Dim rs As Object
Dim f As Object
Dim wbk_creation As Workbook
Set wbk_creation = ActiveWorkbook
If Not CBool(InStr(Adresse, ":")) Then Exit Sub
wbk_creation.Sheets("Feuil1").Select
With CreateObject("Adodb.connection")
.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & wbk_creation.FullName & ";Extended Properties=""Excel 12.0;HDR=no;"""
Set rs = .Execute("Select count([F1]),[F1] from [Feuil1$" & Adresse & "] where [F1] is not null group by [F1] having count([F1])>1")
Set f = wbk_creation.Sheets.Add: f.Cells(1, "A").CopyFromRecordset rs
rs.Close
.Close
End With
End Sub |
Partager