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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Sub CmdP()
Dim bd As Object, dico As Object
Dim dl As Integer, i As Integer, x As Integer, lg As Integer
Dim pl As Range, cel As Range
Dim temp As Variant
Dim enObs As String
'Application.ScreenUpdating = False
Set bd = Sheets("BD") 'définit l'onglet bd
dl = bd.Cells(Application.Rows.Count, 1).End(xlUp).Row
Set pl = bd.Range("B2:B" & dl) 'définit la plage pl
Range("B2:M" & dl).Select 'Tri BD
bd.Sort.SortFields.Add Key:=Range("B2"), SortOn _
:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With bd.Sort
.SetRange Range("B2:M" & dl)
.Apply
End With
bd.Range("A1").AutoFilter Field:=2, Criteria1:="Tiers" 'Filtre1
On Error Resume Next
Set dico = CreateObject("Scripting.Dictionary")
For Each cel In pl.Offset(0, 2).SpecialCells(xlCellTypeVisible)
dico(cel.Value) = ""
Next cel
temp = dico.keys
For i = 0 To UBound(temp)
bd.Range("A1:M" & dl).AutoFilter Field:=2, Criteria1:=Array( _
"Gzc", "Olc", "Tiers"), Operator:=xlFilterValues 'Filtre2
bd.Range("A1").AutoFilter Field:=4, Criteria1:=temp(i) 'Filtre3
If bd.Range("B:B").SpecialCells(xlCellTypeVisible).Areas(1).Count > 1 Then
lg = 2
Else
lg = bd.Range("B:B").SpecialCells(xlCellTypeVisible).Areas(2).Item(1).Row
End If
x = Application.Subtotal(3, [pl])
Set a = Range("B" & Application.Match("Tiers", Range("B1:B" & dl), 0))
MsgBox a.Address
'concatener
If x > 1 Then
enObs = Cells(lg, 13) & Chr(10) & "I " & Range(a.Address).Offset(0, 1) & _
" = " & Range(a.Address).Offset(0, 8) & "mA " & " ; " & Range(a.Address).Offset(0, 13)
enObs = Replace(enObs, Chr(10) & Chr(10), Chr(10))
Cells(lg, 13).Value = enObs
Application.DisplayAlerts = False
Range(a.Address).Rows.Delete
Application.DisplayAlerts = True
End If
Next i
bd.Range("A1").AutoFilter
MsgBox "Terminé!"
End Sub |
Partager