Supprimer toutes les lignes contenant le mot "Representative"

josanche

XLDnaute Occasionnel
Bonjour,

J'aurais besoin de votre aide. Je voudrais savoir comment on fait via un macro ou une autre fonction excel pour supprimer toutes les lignes du fichier excel contenant le mot "Representative" en sachant que les lignes sont du textes ! J'aimerais un macro qui analyse ligne par ligne et supprime chaque ligne de texte contenant le mot "Representative"

Merci pour votre aide

Cordialement
 

Pièces jointes

  • Echantillon.xlsx
    11.1 KB · Affichages: 233
  • Echantillon.xlsx
    11.1 KB · Affichages: 237
  • Echantillon.xlsx
    11.1 KB · Affichages: 262

soan

XLDnaute Barbatruc
Inactif
ou tu veux que je fasse le job à partir du fichier "Echantillon.xlsx"
du demandeur josanche ? (j'ai vu que c'est un sujet de 2012 !)

tu as peut-être un fichier plus récent ? c'est qu'entre-temps,
de l'eau a coulé sous les ponts, lollllllll ! 😛 😁


soan
 

Styv17

XLDnaute Nouveau
en fait ce code la fonctionne bien pour effacer les lignes qui ont le mot "Rich":


Sub Macro1()
Dim Cel As Range
Do
Set Cel = Cells.Find(What:="Rich", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)
If Cel Is Nothing Then
Exit Do
Else
Rows(Cel.Row).Delete
End If
Loop
End Sub


Maintenant toujours en utilisant ce code, est il possible de rajouter une fonction qui dit : si il y a le mot "Precious Alloy" dans cette ligne, ne supprime pas la ligne ?
 

soan

XLDnaute Barbatruc
Inactif
ça y'est, j'ai trouvé ton fichier ; le voici en retour. :)

fais Ctrl e ➯ travail effectué ! 😊

ce que je t'ai indiqué dans mon post #15 est car je pensais que c'était
dans la même phrase qu'il peut y avoir "Rich" et "Precious Alloy" ;
or selon ton fichier : "Rich" apparaît seulement dans la colonne G ;
et "Precious Alloy" apparaît seulement dans la colonne F ; donc la
« stratégie » à adopter est très différente ! voici un autre exemple bien
concret comme quoi il vaut toujours mieux joindre un fichier ! 😜 😁


soan
 

Pièces jointes

  • exemple.xlsm
    16.1 KB · Affichages: 6

fanch55

XLDnaute Barbatruc
Bonjour le fil,
J'aimerai supprimer toutes les lignes contenant le mot " Rich ". Cependant si dans cette même ligne il y a aussi le mot " Precious Alloy ", il ne faudrait pas la supprimer.
Code à tester : (classeur joint pour exemple)
VB:
Sub Test()
Dim Row As Range, Target As Range, To_Del as String
Set Target = Range("A1:E20") ' <-- range bidon à modifier

For Each Row In Target.Rows
    Select Case True
        Case Not SFW(Row, "rich")
        Case Not SFW(Row, "precious alloy")
'       Case Not SFW(Row, "any") <-- pour des restrictions supplémentaires
        Case To_Del = "":   To_Del = Row.Row & ":" & Row.Row
        Case Else:          To_Del = To_Del & "," & Row.Row & ":" & Row.Row
    End Select
Next

If To_Del <> "" Then
    Range(To_Del).Select
    If MsgBox("Voulez-vous détruire les lignes sélectionnées ?", vbCritical + vbYesNo) = vbYes Then
        Selection.Delete
    End If
End If
Cells(1).Activate
  
End Sub
Function SFW(Plage As Range, W As String) As Boolean
Dim Cell_Sel As Range
    Set Cell_Sel = Plage.Find(W, , xlFormulas, xlPart, xlByColumns, xlNext, False)
    If Not Cell_Sel Is Nothing Then
        If Len(Trim(Cell_Sel)) <> Len(W) Then Set Cell_Sel = Nothing
    End If
    SFW = Not Cell_Sel Is Nothing
End Function

Nota: s'adapte également à la demande de @JM-OFF

🤗
 

Pièces jointes

  • Del_Multimots.xlsm
    17 KB · Affichages: 4
Dernière édition:

fanch55

XLDnaute Barbatruc
Merci pour la réponse 👍
Désolé, mal lu la demande, le code tel qu'il est proposé détruit les lignes si on trouve "Rich" et "Precious Alloy" ... o_O

Pour éviter de détruire les lignes avec "Precious Alloy":
VB:
Sub Test()
Dim Row As Range, Target As Range, To_Del As String
Set Target = Range("A1:E20") ' <-- range bidon à modifier

For Each Row In Target.Rows
    Select Case True
        Case Not SFW(Row, "rich")
        Case SFW(Row, "precious alloy") <-- modif! modif ! modif !
 '       Case Not SFW(Row, "....") <-- pour des restrictions supplémentaires
        Case To_Del = "":   To_Del = Row.Row & ":" & Row.Row
        Case Else:          To_Del = To_Del & "," & Row.Row & ":" & Row.Row
    End Select
Next

If To_Del <> "" Then
    Range(To_Del).Select
    If MsgBox("Voulez-vous détruire les lignes sélectionnées ?", vbCritical + vbYesNo) = vbYes Then
        Selection.Delete
    End If
End If
Cells(1).Activate
    
End Sub
Function SFW(Plage As Range, W As String) As Boolean
Dim Cell_Sel As Range
    Set Cell_Sel = Plage.Find(W, , xlFormulas, xlPart, xlByColumns, xlNext, False)
    If Not Cell_Sel Is Nothing Then
        If Len(Trim(Cell_Sel)) <> Len(W) Then Set Cell_Sel = Nothing
    End If
    SFW = Not Cell_Sel Is Nothing
End Function
 

Styv17

XLDnaute Nouveau
Bonjour le fil,

Code à tester : (classeur joint pour exemple)
VB:
Sub Test()
Dim Row As Range, Target As Range, To_Del as String
Set Target = Range("A1:E20") ' <-- range bidon à modifier

For Each Row In Target.Rows
    Select Case True
        Case Not SFW(Row, "rich")
        Case Not SFW(Row, "precious alloy")
'       Case Not SFW(Row, "any") <-- pour des restrictions supplémentaires
        Case To_Del = "":   To_Del = Row.Row & ":" & Row.Row
        Case Else:          To_Del = To_Del & "," & Row.Row & ":" & Row.Row
    End Select
Next

If To_Del <> "" Then
    Range(To_Del).Select
    If MsgBox("Voulez-vous détruire les lignes sélectionnées ?", vbCritical + vbYesNo) = vbYes Then
        Selection.Delete
    End If
End If
Cells(1).Activate
 
End Sub
Function SFW(Plage As Range, W As String) As Boolean
Dim Cell_Sel As Range
    Set Cell_Sel = Plage.Find(W, , xlFormulas, xlPart, xlByColumns, xlNext, False)
    If Not Cell_Sel Is Nothing Then
        If Len(Trim(Cell_Sel)) <> Len(W) Then Set Cell_Sel = Nothing
    End If
    SFW = Not Cell_Sel Is Nothing
End Function

Nota: s'adapte également à la demande de @JM-OFF

🤗

Hello merci pour ta réponse, mais ce code efface les lignes ou il y a "Rich" et "Precious Alloy", alors que c'est le contraire que je cherche. L'idée est de Supprimer toutes les lignes où il y a "Rich" mais de garder les lignes ou il y a "Rich" et "Precious Alloy"
 

soan

XLDnaute Barbatruc
Inactif
@Styv17

mon fichier fait bien ce que tu demandes ! 😊

il supprime toutes les lignes contenant "Rich" sauf s'il y a aussi
"Precious Alloy" !

si tu essayes le fichier de mon post #20, tu verras que c'est OK !
sur les 30 lignes de départ, 20 sont supprimées ; et il reste
donc les 10 lignes que tu attends !


soan
 

Discussions similaires

Statistiques des forums

Discussions
312 246
Messages
2 086 574
Membres
103 247
dernier inscrit
bottxok