Supprimer des lignes ?

Bonsoir j'aimerais une macro qui supprime la ou les lignes qui contiennent PARIS, merci à vous.

18classeur1.zip (10.73 Ko)

Salut le Forum

Une boucle avec le test

If InStr(1, Cells(Ligne, 1), "Paris", 1)>0 then

Mytå

Bonjour à tous,

Voici la boucle

Sub removParis()
    Dim temp, tbl
    Dim i As Long, cpt As Long

    temp = Range("a1").CurrentRegion.Value
    ReDim tbl(1 To UBound(temp), 1 To 1)
    For i = LBound(temp) To UBound(temp)
        If InStr(temp(i, 1), "PARIS") = 0 Then cpt = cpt + 1: tbl(cpt, 1) = temp(i, 1)
    Next i
    Range("a1").CurrentRegion.Value = tbl
End Sub
vba-new a écrit :

Bonjour à tous,

Voici la boucle

Sub removParis()
    Dim temp, tbl
    Dim i As Long, cpt As Long

    temp = Range("a1").CurrentRegion.Value
    ReDim tbl(1 To UBound(temp), 1 To 1)
    For i = LBound(temp) To UBound(temp)
        If InStr(temp(i, 1), "PARIS") <> 0 Then cpt = cpt + 1: tbl(cpt, 1) = temp(i, 1)
    Next i
    Range("a1").CurrentRegion.Value = tbl
End Sub

Cette macro ne conserve que PARIS, je souhaite le contraire.

Autant pour moi, une petite modif dans la macro :

Sub removParis()
    Dim temp, tbl
    Dim i As Long, cpt As Long

    temp = Range("a1").CurrentRegion.Value
    ReDim tbl(1 To UBound(temp), 1 To 1)
    For i = LBound(temp) To UBound(temp)
        If InStr(temp(i, 1), "PARIS") = 0 Then cpt = cpt + 1: tbl(cpt, 1) = temp(i, 1)
    Next i
    Range("a1").CurrentRegion.Value = tbl
End Sub

salut

essaye le fichier joint

il supprime le texte inscrit (respecter la casse)

12classeur1.zip (13.43 Ko)

Merci à vous, ça fonctionne.

Attention, je mets un petit bémol à la solution de babouze64.

Si 2 lignes contenant le mot PARIS se suivent, l'une d'elles ne sera pas supprimée.

Bien que ce ne soit la méthode la plus optimisée (on supprime les lignes une à une), si toutefois tu l'utilises, il faut inverser la boucle pour que ça marche :

Sub supprimer_PARIS()

Application.ScreenUpdating = False
 Dim i&
 Dim rep As Variant
 rep = InputBox("Saisir l'expression a supprimer : ", "Recherche")
 If rep = "" Then Exit Sub
 For i = 1000 To 2 Step -1
     If InStr(1, Cells(i, 1).Value, rep) <> 0 Then
         Rows(i).EntireRow.Delete
     End If
 Next i

 Application.ScreenUpdating = True
 MsgBox ("fin de la suppression")
 End Sub

D'accord, mais si j'ai plusieurs valeurs à supprimer ?

    Sub removParis()
        Dim temp, tbl
        Dim i As Long, cpt As Long

        temp = Range("a1").CurrentRegion.Value
        ReDim tbl(1 To UBound(temp), 1 To 1)
        For i = LBound(temp) To UBound(temp)
            If InStr(temp(i, 1), "PARIS") = 0 Then cpt = cpt + 1: tbl(cpt, 1) = temp(i, 1)
        Next i
        Range("a1").CurrentRegion.Value = tbl
    End Sub

Re le Forum

Dans tes anciennes demandes : Supprimer ... sous conditions

Mytå

Mytå a écrit :

Re le Forum

Dans tes anciennes demandes : Supprimer ... sous conditions

Mytå

C'est pour les colonnes

Re le Forum

Tu veux plusieurs valeurs à rechercher

  NomCol = Array("STOP", "LOUPE", "RATP", "PTT")
  For I = 0 To UBound(NomCol)
    'Ton code ici
  Next I

Mytå

Merci et bon dimanche à toi.

Rechercher des sujets similaires à "supprimer lignes"