Compression d'écritures sous VBA

  • Initiateur de la discussion liloo23
  • Date de début
L

liloo23

Guest
Bonjour à tous

J'ai un petit problème sous VBA, j'aimerai compresser les écritures suivantes, mais je n'ai pas réussi à arriver à mes fins. Si quelqu'un pouvait se pencher sur mon problème. Merci par avance.

Dim lettre As String

If Range('H14') <= 8 Then
lettre = 'Commande 1'
For ligne = 1 To [A65000].End(xlUp).Row
If UCase(Cells(ligne, 1)) = UCase(lettre) Then
For Each WS In Worksheets WS.Rows(ligne).EntireRow.Delete
Next WS
End If
Next ligne
End If

If Range('H14') <= 8 Then
lettre = 'Commande 2'
For ligne = 1 To [A65000].End(xlUp).Row
If UCase(Cells(ligne, 1)) = UCase(lettre) Then
For Each WS In Worksheets WS.Rows(ligne).EntireRow.Delete
Next WS
End If
Next ligne
End If
 

Bebere

XLDnaute Barbatruc
bonsoir Liloo
essaye ce code
supprimer des lignes en commencant par la fin

dim Lettre as string,ligne as integer,Ws as worksheet

lettre = 'Commande 1'
For Each WS In Worksheets
For ligne = [A65000].End(xlUp).Row to 1 step-1
If Range('H14') <= 8 Then
If UCase(Cells(ligne, 1)) = UCase(lettre) Then
WS.Rows(ligne).EntireRow.Delete
End If
Next ligne
Next WS
End If

à bientôt
 
L

liloo23

Guest
Bonjour à toutes et à tous !

Mais si je dois intégrer d'autres mots que 'commande' à macro, comment dois-je procéder ?

Par exemple :

Dim lettre As String

If Range('H14') <= 8 Then
lettre = 'Commande 1'
For ligne = 1 To [A65000].End(xlUp).Row
If UCase(Cells(ligne, 1)) = UCase(lettre) Then
For Each WS In Worksheets WS.Rows(ligne).EntireRow.Delete
Next WS
End If
Next ligne
End If

If Range('H14') <= 8 Then
lettre = 'Livraison'
For ligne = 1 To [A65000].End(xlUp).Row
If UCase(Cells(ligne, 1)) = UCase(lettre) Then
For Each WS In Worksheets WS.Rows(ligne).EntireRow.Delete
Next WS
End If
Next ligne
End If

Merci par avance
 

Bebere

XLDnaute Barbatruc
bonjour Liloo


dim Lettre(3) as string
dim ligne as integer,Ws as worksheet
dim I as integer

lettre(0)='cde1'
lettre(1)='cde2'
lettre(2)='cde3'
lettre(3)='cde4'

for i=0 to 3
For Each WS In Worksheets
For ligne = [A65000].End(xlUp).Row to 1 step-1
If Range('H14') <= 8 Then
If UCase(Cells(ligne, 1)) = UCase(lettre(i)) Then
WS.Rows(ligne).EntireRow.Delete
End If
Next ligne
Next WS
End If
next i

à bientôt
 

Bebere

XLDnaute Barbatruc
bonjour Liloo

effectivement,regarde les endif
c'est là qu'était la faute

un petit conseil,la prochaine fois mets un fichier avec des données(un extrait)et ton code
comme cela on pourra tester

dim Lettre(3) as string
dim ligne as integer,Ws as worksheet
dim I as integer

lettre(0)='cde1'
lettre(1)='cde2'
lettre(2)='cde3'
lettre(3)='cde4'

for i=0 to 3
For Each WS In Worksheets
For ligne = [A65000].End(xlUp).Row to 1 step-1
If Range('H14') <= 8 Then
If UCase(Cells(ligne, 1)) = UCase(lettre(i)) Then
WS.Rows(ligne).EntireRow.Delete
End If
End If
Next ligne
Next WS
next i

à bientôt
 

Discussions similaires

Statistiques des forums

Discussions
312 413
Messages
2 088 200
Membres
103 762
dernier inscrit
rouazali