Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

manulemalin13000

XLDnaute Occasionnel
Bonjour,

J'ai la macro suivante, tres courte qui efface completement une ligne qui contient tel ou tel mot.
Chaque fois que je veux changer de mot je dois modifier la macro.
Serait il possible que quand je lance ma macro une boite de dialogue s ouvre, je rentre le mot et en faisant ok ca s'execute ?

merci pour votre aide


Ici le mot etait SHUTDOWN

Sub test()
Dim cellRecherche As Range
Set cellRecherche = ActiveSheet.Cells.Find("SHUTDOWN", , , xlPart)
While Not cellRecherche Is Nothing
cellRecherche.EntireRow.Delete
Set cellRecherche = ActiveSheet.Cells.Find("SHUTDOWN", , , xlPart)
Wend
End Sub
 
Re : boite de dialogue

Bonjour manulemalin13000,

Vite fait sans essai :

Sub test()
Dim cellRecherche As Range, LeMot As String
LeMot = InputBox("Saisissez le mot à chercher, merci ", "RECHERCHE D'UN MOT", vbOKCancel)
If LeMot = "" Then Exit Sub
Set cellRecherche = ActiveSheet.Cells.Find(LeMot, , , xlPart)
While Not cellRecherche Is Nothing
cellRecherche.EntireRow.Delete
Set cellRecherche = ActiveSheet.Cells.Find(LeMot, , , xlPart)
Wend
End Sub
 
Re : boite de dialogue

Bonjour manulemalin,

Modifie ta macro comme ceci :

Code:
Sub test()
Dim cellRecherche As Range, Mot As String
Mot = InputBox("Mot à rechercher", "Effacement ligne")
Set cellRecherche = ActiveSheet.Cells.Find(Mot, , , xlPart)
While Not cellRecherche Is Nothing
cellRecherche.EntireRow.Delete
Set cellRecherche = ActiveSheet.Cells.Find(Mot, , , xlPart)
Wend
End Sub

Bonne journée.

Cordialement.

Edit : Bonjour Bernard,
Ta macro, identique à la mienne, doit fonctionner puisque j'ai testé ma solution (d'où mon leger retard sur toi).

Cordialement.
 
Dernière édition:
Re : boite de dialogue

Bonjour à tous,

une autre approche :
Code:
Option Explicit
Sub test()
Dim t As String, x As Range
t = InputBox("mot recherché ?")
If t = "" Then Exit Sub
With ActiveSheet.Cells
    Set x = .Find(t, , xlValues, xlPart, , , False)
    If Not x Is Nothing Then
        Do
            Rows(x.Row).Delete
            Set x = .FindNext
        Loop While Not x Is Nothing
    End If
End With
End Sub

bonne journée
@+
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
21
Affichages
2 K
Retour