Salut,
Finalement, j'y suis arrivé... Il faut que je teste encore, mais j'ai l'impression que j'ai réussi à déclarer toutes les combinaisons possibles ... Il y a certainement plus simple mais ... Alors voilà :Sub countoccurencestestb()
'
' countoccurences Macro
Dim x As Long, y As Long, z As Long, u As Long, v As Long, w As Long, n As Long, o As Long, p As Long, a As Long, b As Long, i As Long, j As Long
Dim Toto As Range, c As Range, rngRed As Range
Dim iCol As Integer
Set Toto = Range("A2")
If WorksheetFunction.CountA(Columns("B:D")) = 0 Then GoTo Colonne2
x = Application.WorksheetFunction.CountIf(Range("C:C"), "mange")
y = Application.WorksheetFunction.CountIf(Range("C:C"), "boit")
z = Application.WorksheetFunction.CountIf(Range("C:C"), "dort")
a = x
If x 0 And y 0 Then GoTo RepseulC
If a = 0 Then GoTo Miss
If x > 0 Then
Range("B1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "mange1"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(x).Insert xlShiftDown
For Each c In ActiveSheet.Range("C:C")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("B1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
x = 0
b = y
If b = 0 Then GoTo Rep
If y > 0 Then
Range("C1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit1"
Toto.Offset(1, 0).Activate
ActiveCell.EntireRow.Resize(y).Insert xlShiftDown
For Each c In ActiveSheet.Range("C:C")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("C1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
y = 0
If z > 0 Then
Range("D1").Activate
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.EntireColumn.Offset(0, 1).Insert
numColumns = numColumns + 1
Range("D1").Activate
ActiveCell.Value = "dort1"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(z).Insert xlShiftDown
For Each c In ActiveSheet.Range("C:C")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("D1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("E1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
z = 0
u = Application.WorksheetFunction.CountIf(Range("G:G"), "mange")
If u > 0 Then
Range("F1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "manget2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(u).Insert xlShiftDown
For Each c In ActiveSheet.Range("G:G")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("F1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
u = 0
v = Application.WorksheetFunction.CountIf(Range("G:G"), "boit")
If v > 0 Then
Range("G1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(v).Insert xlShiftDown
For Each c In ActiveSheet.Range("G:G")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("G1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
v = 0
w = Application.WorksheetFunction.CountIf(Range("G:G"), "dort")
If w > 0 Then
Range("H1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("H1").Select
ActiveCell.Value = "dort2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(w).Insert xlShiftDown
For Each c In ActiveSheet.Range("G:G")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("H1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("I1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
w = 0
n = Application.WorksheetFunction.CountIf(Range("K:K"), "mange")
If n > 0 Then
Range("J1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "mange3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(n).Insert xlShiftDown
For Each c In ActiveSheet.Range("K:K")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("J1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
n = 0
o = Application.WorksheetFunction.CountIf(Range("K:K"), "boit")
If o > 0 Then
Range("K1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(o).Insert xlShiftDown
For Each c In ActiveSheet.Range("K:K")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("K1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
o = 0
p = Application.WorksheetFunction.CountIf(Range("K:K"), "dort")
If p > 0 Then
Range("L1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("L1").Select
ActiveCell.Value = "dortt3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(p).Insert xlShiftDown
For Each c In ActiveSheet.Range("K:K")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("L1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("M1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
p = 0
Miss:
b = y
If y > 0 Then
Range("B1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit1"
Toto.Offset(1, 0).Activate
ActiveCell.EntireRow.Resize(y).Insert xlShiftDown
For Each c In ActiveSheet.Range("C:C")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("B1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
y = 0
If z > 0 Then
Range("C1").Activate
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
numColumns = numColumns + 1
Range("C1").Activate
ActiveCell.Value = "dort1"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(z).Insert xlShiftDown
For Each c In ActiveSheet.Range("C:C")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("C1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("D1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
z = 0
u = Application.WorksheetFunction.CountIf(Range("F:F"), "mange")
If u > 0 Then
Range("E1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "manget2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(u).Insert xlShiftDown
For Each c In ActiveSheet.Range("F:F")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("E1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
u = 0
v = Application.WorksheetFunction.CountIf(Range("F:F"), "boit")
If v > 0 Then
Range("F1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(v).Insert xlShiftDown
For Each c In ActiveSheet.Range("F:F")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("F1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
v = 0
w = Application.WorksheetFunction.CountIf(Range("F:F"), "dort")
If w > 0 Then
Range("G1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("G1").Select
ActiveCell.Value = "dort2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(w).Insert xlShiftDown
For Each c In ActiveSheet.Range("F:F")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("G1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("H1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
w = 0
n = Application.WorksheetFunction.CountIf(Range("J:J"), "mange")
If n > 0 Then
Range("I1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "mange3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(n).Insert xlShiftDown
For Each c In ActiveSheet.Range("J:J")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("I1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
n = 0
o = Application.WorksheetFunction.CountIf(Range("J:J"), "boit")
If o > 0 Then
Range("J1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(o).Insert xlShiftDown
For Each c In ActiveSheet.Range("J:J")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("J1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
o = 0
p = Application.WorksheetFunction.CountIf(Range("J:J"), "dort")
If p > 0 Then
Range("K1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("K1").Select
ActiveCell.Value = "dortt3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(p).Insert xlShiftDown
For Each c In ActiveSheet.Range("J:J")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("K1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("L1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
p = 0
RepseulC:
MsgBox "debut RepseulC"
If z > 0 Then
Range("B1").Select
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
Range("B1").Activate
ActiveCell.Value = "dort1"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(z).Insert xlShiftDown
MsgBox "Stop"
For Each c In ActiveSheet.Range("D:D")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -2).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("B1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("C1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
z = 0
u = Application.WorksheetFunction.CountIf(Range("G:G"), "mange")
If u > 0 Then
Range("F1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "manget2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(u).Insert xlShiftDown
For Each c In ActiveSheet.Range("G:G")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("F1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
u = 0
v = Application.WorksheetFunction.CountIf(Range("G:G"), "boit")
If v > 0 Then
Range("G1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(v).Insert xlShiftDown
For Each c In ActiveSheet.Range("G:G")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("G1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
v = 0
w = Application.WorksheetFunction.CountIf(Range("G:G"), "dort")
If w > 0 Then
Range("H1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("H1").Select
ActiveCell.Value = "dort2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(w).Insert xlShiftDown
For Each c In ActiveSheet.Range("G:G")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("H1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("I1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
w = 0
n = Application.WorksheetFunction.CountIf(Range("K:K"), "mange")
If n > 0 Then
Range("J1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "mange3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(n).Insert xlShiftDown
For Each c In ActiveSheet.Range("K:K")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("J1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
n = 0
o = Application.WorksheetFunction.CountIf(Range("K:K"), "boit")
If o > 0 Then
Range("K1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(o).Insert xlShiftDown
For Each c In ActiveSheet.Range("K:K")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("K1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
o = 0
p = Application.WorksheetFunction.CountIf(Range("K:K"), "dort")
If p > 0 Then
Range("L1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("L1").Select
ActiveCell.Value = "dortt3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(p).Insert xlShiftDown
For Each c In ActiveSheet.Range("K:K")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("L1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("M1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
p = 0
Rep:
If z > 0 Then
Range("C1").Activate
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
numColumns = numColumns + 1
Range("C1").Activate
ActiveCell.Value = "dort1"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(z).Insert xlShiftDown
For Each c In ActiveSheet.Range("C:C")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("C1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("D1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
z = 0
u = Application.WorksheetFunction.CountIf(Range("F:F"), "mange")
If u > 0 Then
Range("E1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "manget2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(u).Insert xlShiftDown
For Each c In ActiveSheet.Range("F:F")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("E1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
u = 0
v = Application.WorksheetFunction.CountIf(Range("F:F"), "boit")
If v > 0 Then
Range("F1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(v).Insert xlShiftDown
For Each c In ActiveSheet.Range("F:F")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("F1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
v = 0
w = Application.WorksheetFunction.CountIf(Range("F:F"), "dort")
If w > 0 Then
Range("G1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("G1").Select
ActiveCell.Value = "dort2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(w).Insert xlShiftDown
For Each c In ActiveSheet.Range("F:F")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("G1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("H1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
w = 0
n = Application.WorksheetFunction.CountIf(Range("J:J"), "mange")
If n > 0 Then
Range("I1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "mange3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(n).Insert xlShiftDown
For Each c In ActiveSheet.Range("J:J")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("I1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
n = 0
o = Application.WorksheetFunction.CountIf(Range("J:J"), "boit")
If o > 0 Then
Range("J1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(o).Insert xlShiftDown
For Each c In ActiveSheet.Range("J:J")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("J1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
o = 0
p = Application.WorksheetFunction.CountIf(Range("J:J"), "dort")
If p > 0 Then
Range("K1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("K1").Select
ActiveCell.Value = "dortt3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(p).Insert xlShiftDown
For Each c In ActiveSheet.Range("J:J")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("K1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("L1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
p = 0
Colonne2:
u = Application.WorksheetFunction.CountIf(Range("F:F"), "mange")
If u > 0 Then
Range("B1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "manget2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(u).Insert xlShiftDown
For Each c In ActiveSheet.Range("F:F")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("B1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
u = 0
v = Application.WorksheetFunction.CountIf(Range("F:F"), "boit")
If v > 0 Then
Range("C1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(v).Insert xlShiftDown
For Each c In ActiveSheet.Range("F:F")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("C1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
v = 0
w = Application.WorksheetFunction.CountIf(Range("F:F"), "dort")
If w = 0 Then GoTo RienABCpasdortdansF
If w > 0 Then
Range("D1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("D1").Select
ActiveCell.Value = "dort2"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(w).Insert xlShiftDown
For Each c In ActiveSheet.Range("G:G")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("D1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("E1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
w = 0
n = Application.WorksheetFunction.CountIf(Range("J:J"), "mange")
If n > 0 Then
Range("F1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "mange3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(n).Insert xlShiftDown
For Each c In ActiveSheet.Range("J:J")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("F1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
n = 0
o = Application.WorksheetFunction.CountIf(Range("J:J"), "boit")
If o > 0 Then
Range("G1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(o).Insert xlShiftDown
For Each c In ActiveSheet.Range("J:J")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("G1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
o = 0
p = Application.WorksheetFunction.CountIf(Range("J:J"), "dort")
If p > 0 Then
Range("H1").Activate
ActiveCell.EntireColumn.Offset(0, 1).Insert
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("H1").Select
ActiveCell.Value = "dortt3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(p).Insert xlShiftDown
For Each c In ActiveSheet.Range("K:K")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("H1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("I1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
p = 0
RienABCpasdortdansF:
MsgBox "RienABCpasdortdansF"
n = Application.WorksheetFunction.CountIf(Range("I:I"), "mange")
If n > 0 Then
Range("H1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "mange3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(n).Insert xlShiftDown
For Each c In ActiveSheet.Range("I:I")
If c.Value = "mange" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("H1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
n = 0
o = Application.WorksheetFunction.CountIf(Range("I:I"), "boit")
If o > 0 Then
Range("I1").Select
NumRows = Selection.Rows.Count
numColumns = Selection.Columns.Count
ActiveCell.Value = "boit3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(o).Insert xlShiftDown
For Each c In ActiveSheet.Range("I:I")
If c.Value = "boit" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("I1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
o = 0
p = Application.WorksheetFunction.CountIf(Range("I:I"), "dort")
If p > 0 Then
Range("J1").Activate
NumRows = Selection.Rows.Count
numColumns = numColumns + 1
Range("J1").Select
ActiveCell.Value = "dortt3"
Toto.Offset(1, 0).Select
ActiveCell.EntireRow.Resize(p).Insert xlShiftDown
For Each c In ActiveSheet.Range("I:I")
If c.Value = "dort" Then
If rngRed Is Nothing Then Set rngRed = c
rngRed.Offset(0, -1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("J1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.Offset(0, 1).Activate
Selection.Copy
ActiveSheet.Paste Destination:=Range("K1").Offset(NumRows + 1, 0)
Selection.ClearContents
rngRed.ClearContents
NumRows = NumRows + 1
Set rngRed = Nothing
End If
Next c
End If
p = 0
With ActiveSheet.UsedRange
For iCol = .Column + .Columns.Count - 1 To 1 Step -1
If IsEmpty(Cells(65536, iCol)) And IsEmpty(Cells(1, iCol)) Then
If Cells(65536, iCol).End(xlUp).Row = 1 Then Columns(iCol).mange
End If
Next iCol
End With
End Sub
Bonne fin d'année !