Private Sub Worksheet_Change(ByVal Target As Range)
If [A2] = "" Then [A2] = Application.CountIf([2:2], "QL*")
If [B2] = "" Then [B2] = Application.CountIf([2:2], "VR*")
If Not Intersect(Target, [A2]) Is Nothing Then Insertion [A2], "QL"
If Not Intersect(Target, [B2]) Is Nothing Then Insertion [B2], "VR"
End Sub
Sub Insertion(c As Range, txt$)
Dim coldeb%, colfin%, n%, r As Range
'---1ère colonne---
coldeb = Application.Match(txt & 1, [2:2], 0)
'---dernière colonne---
colfin = [2:2].Find(txt & "*", , xlValues, xlWhole, , xlPrevious).Column
'---suppression ou insertion de colonnes---
If colfin - coldeb + 1 > c Then
Columns(coldeb + c).Resize(, colfin - coldeb + 1 - c).Delete
ElseIf colfin - coldeb + 1 < c Then
Columns(colfin + 1).Resize(, c - colfin + coldeb - 1).Insert
Cells(1, coldeb).Resize(, c).Merge 'fusion
Cells(2, coldeb).AutoFill Cells(2, coldeb).Resize(, c) 'remplissage
n = Application.CountIf([B:B], "CA PLANIFIES")
Set r = [B1]
For n = 1 To n
Set r = [B:B].Find("CA PLANIFIES", r)
Cells(r.Row, coldeb).Resize(2).Copy Cells(r.Row, coldeb + 1).Resize(2, c - 1)
Next
End If
Columns.AutoFit 'ajustement de la largeur
End Sub