1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Dim I As Long, Deb As Long, Fin As Long
With ActiveSheet
For I = .UsedRange.Column + .UsedRange.Columns.Count To 1 Step -1
If .Cells(6, I).Value <> "Niveau" And .Cells(6, I).Value <> "Version" And .Cells(6, I).Value <> "Référence" And .Cells(6, I).Value <> "Nom" _
And .Cells(6, I).Value <> "Statut" And .Cells(6, I).Value <> "Type" And .Cells(6, I).Value <> "huile" And .Cells(6, I).Value <> "vente" _
And .Cells(6, I).Value <> "Numr" And .Cells(6, I).Value <> "region" _
And .Cells(6, I).Value <> "client" And .Cells(6, I).Value <> "mod" And .Cells(6, I).Value <> "Stru" _
And .Cells(6, I).Value <> "crochet" Then
If Fin = 0 Then Fin = I ' on débute un nouveau bloc, de droite à gauche donc on a sa dernière colonne
Else
' on est sur une bonne colonne, si un bloc était en cours, la précédente termine le bloc
' (donc la première colonne du bloc puisqu'on va de D à G)
If Fin <> 0 Then Deb = I + 1
End If
If Deb <> 0 Then 'on vient de finir de déterminer un bloc
.Range(.Columns(Deb), .Columns(Fin)).Delete
' et on réinitialise en attendant le prochain bloc
Deb = 0
Fin = 0
End If
Next I
' Dernier delete
If Fin > 0 Then .Range(.Columns(1), .Columns(Fin)).Delete
End With |
Partager