Suppression de colonne sous condition

nak

XLDnaute Occasionnel
Bonjour,
J'ai une macro qui supprime les lignes entières d'une feuille lorque je trouve Total* en colonne A ou D.
Sub Macro1()
Dim i As Integer
Application.ScreenUpdating = False
For i = 2000 To 1 Step -1
If UCase(Range("A" & i).Value) Like "TOTAL*" Or UCase(Range("D" & i).Value) Like "TOTAL*" Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub

Je voudrais ajouter la suppression de certaines colonnes sous condition avant de supprimer les lignes. Soit effacer les colonnes lorsque reference* ou fabricant* sont présent en ligne 4. J'ai essayé de modifier celle-ci mais sans succès. Pouvez vous m'aider SVP ?

Sub Macro1()
Dim i As Integer
Application.ScreenUpdating = False
For i = 40To 1 Step +1
If UCase(Rows("4" & i).Value) Like "REFERENCE*" Or UCase(Rows("4" & i).Value) Like "FABRICANT*" Then Range(i).Delete
Next i
For i = 2000 To 1 Step -1
If UCase(Range("A" & i).Value) Like "TOTAL*" Or UCase(Range("D" & i).Value) Like "TOTAL*" Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub

Merci
 

skoobi

XLDnaute Barbatruc
Re : Suppression de colonne sous condition

Bonjour nak,

mes changements en rouge:

Code:
Sub Macro1()
Dim i As Integer
Application.ScreenUpdating = False
For i = 40 To 1 Step [B][COLOR=red]-1[/COLOR][/B]
If UCase([COLOR=red][B]Cells(4, i).[/B][COLOR=black]Value[/COLOR][/COLOR]) Like "REFERENCE*" Or UCase([COLOR=red][B]Cells(4, i).[/B][/COLOR]Value) Like "FABRICANT*" Then [COLOR=red][B]Columns[/B][/COLOR](i).Delete
Next i
For i = 2000 To 1 Step -1
If UCase(Range("A" & i).Value) Like "TOTAL*" Or UCase(Range("D" & i).Value) Like "TOTAL*" Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub
 

Discussions similaires