Oups, j'avais pas compris, autant pour moi :
voilà le code :
Sub ExtraireParGroupeColonneB()
Dim O As Long, NbLg As Long
Dim n As Integer
Dim H1 As Worksheet
Dim Mondico As Object
Dim Tablo
Dim Interdits
Dim ligne
Call RegrouperLesBD
Interdits = Array("&", ":", "/", "\", "~?", "~*", "[", "]", Chr(34))
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.DisplayAlerts = True
Call SupprimeFeuille
Set H1 = Sheets("BD")
If H1.FilterMode = True Then H1.ShowAllData
NbLg = H1.Range("A" & Rows.Count).End(xlUp).Row
rep = InputBox("Choisir la lettre de la colonne pour la création de fiches", "CREATION DE FICHES PAR GROUPES", "B")
H1.Columns(rep).Copy H1.Columns("O")
With H1.Range("O2:O" & NbLg)
For n = 0 To UBound(Interdits)
.Replace what:=Interdits(n), replacement:="_", lookat:=xlPart
Next n
End With
Set Mondico = CreateObject("Scripting.dictionary")
For O = 2 To NbLg
Mondico(H1.Range("O" & O).Value) = ""
Next O
H1.Range("O1:P1") = "XYZ"
Tablo = Mondico.keys
For n = 0 To UBound(Tablo)
Sheets.Add(after:=Sheets(Sheets.Count)).Name = Tablo(n)
Sheets("Modèle").UsedRange.Copy
Sheets(Tablo(n)).Range("A1").PasteSpecial
With Sheets(Tablo(n))
.Range("A2") = Tablo(n)
H1.Range("P2") = Tablo(n)
For Each cel In H1.Range("G2:G" & NbLg) 'pour chaque cellule de G2 à G_DernièreLigne
r = cel.Row
noms = H1.Range("C" & r)
If H1.Range(rep & r) = Tablo(n) Then
c = .Range("A1000").End(xlUp).Row + 1
If .Range("A9") = "" Then
H1.Range("C" & r & ":H" & r).Copy 'Copie de C à H feuille BD
.Range("A" & c).PasteSpecial xlPasteValues 'Colle depuis A feuille modèle
End If
If Not .Range("E9:E" & c).Find(cel) Is Nothing And Not .Range("A9:A" & c).Find(noms) Is Nothing Then
'Si le numero de pièce existe déjà dans la feuille modèle alors...
Set ligne = .Range("E9:E" & c).Find(cel) 'on trouve la ligne correspondante
If Not ligne Is Nothing And .Range("A" & ligne.Row) <> noms Then
Flig = ligne.Row
Do
cel.Value = cel
Set ligne = .Range("E9:E" & c).FindNext(.Range("E" & Flig))
ligne = ligne.Row
Loop While ligne = Flig And .Range("A" & ligne) <> noms
Else
ligne = ligne.Row
End If
remp:
'On prend chaque cas de compte et on vient mettre le débit et crédit dans les colonnes correspondantes
If H1.Range("A" & r) = "VACANCES - COLOS" Then .Range("G" & ligne) = .Range("G" & ligne) + H1.Range("I" & r): .Range("H" & ligne) = .Range("H" & ligne) + H1.Range("J" & r)
If H1.Range("A" & r) = "ALIMENTATION A L'EXTERIEUR." Then .Range("I" & ligne) = .Range("I" & ligne) + H1.Range("I" & r): .Range("J" & ligne) = .Range("J" & ligne) + H1.Range("J" & r)
If H1.Range("A" & r) = "AUTRES REMB.FRAIS GR 1" Then .Range("N" & ligne) = .Range("N" & ligne) + H1.Range("J" & r): .Range("M" & ligne) = .Range("M" & ligne) + H1.Range("I" & r)
Else
H1.Range("C" & r & ":H" & r).Copy
.Range("A" & c).PasteSpecial xlPasteValues
ligne = c
GoTo remp
End If
End If
Next cel
ActiveWindow.DisplayOutline = False
End With
'ICI AJUSTER LIGNES ET COLONNES
Call MiseEnPageFeuilleModeleColonnesEtLignes
Next n
H1.Columns("O:P").Clear
H1.Select
Call consolidation
End Sub