Astuce pour simplifier la procédure if then

Bonjour,

Je vous demande juste un petit astuce pour simplifier ma procédure de VBA.

Je pense que c'est très facile pour vous. Voici mes codes:

dim toto as string
for i=1 to 100
toto = Trim(Range("C" & i))
If Left(toto, 4) = "PART" Then
rows(i).delete
ElseIf Left(toto, 3) = "PRL" Then
rows(i).delete
ElseIf Left(toto, 4) = "SENT" Then
rows(i).delete
end if
next i

chaque condition rend le meme résutat, je pensais de mettre GoTo ETIQUETTE comme ce-ci:

for i=...
If Left(toto, 4) = "PART" Then
GoTo ETIQUETTE
end if
ETIQUETTE:
rows(i).delete
next i

ca ne marche pas.

Merci d'avance

Bonjour,

Tu cherches à simplifier ta procédure ... mais est-ce-qu'en l'état actuel ... elle fonctionne comme tu le veux ?

Tu cherches à simplifier ta procédure ... mais est-ce-qu'en l'état actuel ... elle fonctionne comme tu le veux ?

Oui, ca fonctionne, mais c'est avec une facon très "bête" qui répète une action tout le temps, et je la trouve pas très dynamique.

Je voudrais bien connaitre la facon plus "maline"

Bonjour

Sub Supprimer()
Dim toto
For i = [C65000].End(xlUp).Row To 1 Step -1
toto = Application.WorksheetFunction.Trim(i)
If Left(Trim(Range("c" & toto)), 4) = "PART" Or Left(Trim(Range("c" & toto)), 3) = "PRL" Or _
Left(Trim(Range("c" & toto)), 4) = "SENT" Then
Rows(i).EntireRow.Delete
End If
Next i
End Sub

Cordialement

Re,

Ci-joint une proposition ...

Sub SupprimerLignes()
Dim i As Long
Dim arCrit As Variant
Dim arVal As Variant

Application.DisplayAlerts = False
arCrit = Array("PART", "PRL", "SENT")
With Worksheets("Sheet2")
  For i = 100 To 2 Step -1
    For Each arVal In arCrit
      If InStr(1, .Range("C" & i).Value, arVal) >= 1 Then .Rows(i).Delete
    Next arVal
  Next i
End With
Application.DisplayAlerts = True

End Sub

Edit : salut Amadeus

Rechercher des sujets similaires à "astuce simplifier procedure then"