Supprimer un ligne qui ne contient pas un mot

Bonjour,

Je suis débutante en VBA et je souhaite trier une liste excel.

Dans le tableau , j'aimerai supprimer les lignes qui ne contiennent pas les texte suivant:

Carc. 1B

Carc. 1A

Repr. 1B

Repr. 1A

Muta. 1B

Muta. 1A

Est ce possible avec une macro ?

J'ai essayer la macro suivante mais cela m'efface tout

Sub Supp()

Dim I As Integer

For I = [A65000].End(xlUp).Row To 1 Step -1

If Cells(I, 1).Find("Carc. 1B") Is Nothing Or _

Cells(I, 1).Find("Carc. 1A") Is Nothing Or _

Cells(I, 1).Find("Repr. 1B") Is Nothing Or _

Cells(I, 1).Find("Repr. 1A") Is Nothing Or _

Cells(I, 1).Find("Muta. 1B") Is Nothing Or _

Cells(I, 1).Find("Muta. 1A") Is Nothing Then Rows(I).Delete

Next I

End Sub

Merci par avance de votre aide

Elodie

Bonjour,

la recherche de ces textes doit etre effectuée que dans la colonne A ou ça peut aussi etre dans une autre colonne ?

Bonjour,

La recherche est uniquement sur la colonne E.

Je viens de me rendre compte que j'ai copié le mauvais code

Sub Supp()

Dim I As Integer

For I = [E65000].End(xlUp).Row To 1 Step -1

If Cells(I, 1).Find("Carc. 1B") Is Nothing Or _

Cells(I, 1).Find("Carc. 1A") Is Nothing Or _

Cells(I, 1).Find("Repr. 1B") Is Nothing Or _

Cells(I, 1).Find("Repr. 1A") Is Nothing Or _

Cells(I, 1).Find("Muta. 1B") Is Nothing Or _

Cells(I, 1).Find("Muta. 1A") Is Nothing Then Rows(I).Delete

Next I

End Sub

ReBonjour,

A tester (un peu long à l'exécution)

Sub melch()

derlig = Cells(Rows.Count, 5).End(xlUp).Row

For i = derlig To 7 Step -1

    variable = InStr(Cells(i, 5), "Carc. 1B") + InStr(Cells(i, 5), "Carc. 1A") + InStr(Cells(i, 5), "Repr. 1B") + InStr(Cells(i, 5), "Repr. 1A") + InStr(Cells(i, 5), "Muta. 1B") + InStr(Cells(i, 5), "Muta. 1A")
    If variable = 0 Then Cells(i, 1).EntireRow.Delete

Next

End Sub

Merci beaucoup.

Cela fonctionne. Je ne connais pas la fonction InStr. Cela permet de rechercher et donne une valeur ?

ReBonjour,

Instr("Bonjour","j")

Par exemple, cela nous permet de chercher "j" dans "bonjour". Celà nous renvoie 4 car "j" est en 4ème position. Si ça n'a pas été trouvé, cela renvoi 0.

Par conséquent, en ajoutant tous les "Instr", si la somme est égale à 0, c'est qu'il n'a rien trouvé, donc on supprime.

Merci pour ces explication. Je comprends mieux

Bonne journée

Bonjour,

Pour le principe.

On ne fait qu'une suppression !...

Cdlt.

Public Sub Delete_Rows()
Dim lastRow As Long, lRow As Long, v As Long
Dim rng As Range
    Application.ScreenUpdating = False
    With ActiveSheet
        lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        For lRow = 7 To lastRow
            v = InStr(.Cells(lRow, 5), "Carc. 1B") + InStr(.Cells(lRow, 5), "Carc. 1A") _
                + InStr(.Cells(lRow, 5), "Repr. 1B") + InStr(.Cells(lRow, 5), "Repr. 1A") _
                + InStr(.Cells(lRow, 5), "Muta. 1B") + InStr(.Cells(lRow, 5), "Muta. 1A")
            If v = 0 Then
                If rng Is Nothing Then
                    Set rng = .Cells(lRow, 5)
                Else
                    Set rng = Union(rng, .Cells(lRow, 5))
                End If
            End If
        Next lRow
        If Not rng Is Nothing Then rng.EntireRow.Delete
    End With
End Sub

Merci bien

Rechercher des sujets similaires à "supprimer ligne qui contient pas mot"