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
| Dim SynthDct As New Scripting.Dictionary, OccurDct As Scripting.Dictionary
Dim iRow As Long, ShtSrc As Worksheet, ShtImp As Worksheet, sKey As String, sSynth As String, nSynth As Long
Dim Lastline_import As Long, Lastline_src As Long, sBBc As String, sQst As String, sPays As String
Set ShtSrc = Workbooks("Repartition_des_BB_niveau.xlsm").Sheets("Correspondance")
Set ShtImp = ActiveWorkbook.Sheets("Import")
Lastline_src = ShtSrc.Cells(ShtSrc.Rows.Count, 2).End(xlUp).Row
Lastline_import = ShtImp.Cells(ShtImp.Rows.Count, 2).End(xlUp).Row
'Récupération des données source
For iRow = 2 to Lastline_src
sBBc = ShtSrc.Cells(iRow, 1).Text 'Numéro de colonne à adapter ! (BB code, dans Source)
sQst = ShtSrc.Cells(iRow, 2).Text 'Numéro de colonne à adapter ! (Question, dans Source)
sPays = ShtSrc.Cells(iRow, 3).Text 'Numéro de colonne à adapter ! (Pays, dans Source)
sKey = sBBc & "\\" & sQst
If SynthDct.Exists(sKey) Then
Set OccurDct = SynthDct(sKey)
If OccurDct.Exists(sPays) Then
OccurDct(sPays) = OccurDct(sPays) + 1
Else
OccurDct.Add sPays, 1
End If
Else
Set OccurDct = New Scripting.Dictionary
OccurDct.Add sPays, 1
SynthDct.Add sKey, OccurDct
End If
Next iRow
'Passage en revue des lignes d'import
For iRow = 2 to Lastline_import
sBBc = ShtImp.Cells(iRow, 1).Text 'Numéro de colonne à adapter ! (BB code, dans Import)
sQst = ShtImp.Cells(iRow, 2).Text 'Numéro de colonne à adapter ! (Question, dans Import)
sPays = ShtImp.Cells(iRow, 3).Text 'Numéro de colonne à adapter ! (Pays, dans Import)
sKey = sBBc & "\\" & sQst
If SynthDct.Exists(sKey) Then
Set OccurDct = SynthDct(sKey)
sSynth = ""
nSynth = 0
For Each Itm In OccurDct
sSynth = sSynth & Itm & " : " & OccurDct(Itm) & " | "
nSynth = nSynth + OccurDct(Itm)
Next Itm
ShtImp.Cells(iRow, 4).Value = nSynth 'Numéro de colonne à adapter ! (Nb d'occurrences total, dans Import)
ShtImp.Cells(iRow, 5).Value = Left(sSynth, Len(sSynth) - 3) 'Numéro de colonne à adapter ! (Liste Pays, dans Import)
Else
ShtImp.Cells(iRow, 4).Value = 0 'Numéro de colonne à adapter ! (Nb d'occurrences total, dans Import)
End If
Next iRow |
Partager