[ RESOLU] macro qui colorie la ligne selectionné

yvioland

XLDnaute Nouveau
Bonjour a tous,
j'ai une macro qui me donne m'aide a trouver une cellule a partir d'un mot clef. quand cette cellule est selectionné, elle est painte en rouge. J'aimerais cependant qu'elle me colorie toit la ligne. que doit je changer dans ma macro.

Private Sub CommandButton1_Click()
'
' Macro1 Macro
' Macro enregistrée le 26/05/2011 par cmi
'Private Sub mot a recherché_Click()

mot = InputBox("Mot à rechercher ? (mot simple)")
If mot = "" Then Exit Sub

For feuille = 1 To Sheets.Count

Sheets(feuille).Select
Set trouvé1 = Cells.Find(What:=mot)
If Not trouvé1 Is Nothing Then

With trouvé1
.Activate
.Select
.Interior.ColorIndex = 3
End With

étiq:
If MsgBox("Suivant ?", 4) = vbNo Then Exit Sub
Set trouvé2 = Cells.FindNext(After:=ActiveCell)
Set trouvé3 = Cells.FindPrevious(After:=ActiveCell)

Do While trouvé2 <> trouvé1

With trouvé1
.Select
.Font.ColorIndex = 0
End With
With trouvé3
.Select
.Font.ColorIndex = 0
End With
With trouvé2
.Activate
.Select
.Interior.ColorIndex = 3

End With

GoTo étiq

Loop
End If
Next feuille

MsgBox "PLUS DE RESUSLTAT"

End Sub
 
Dernière édition:

yvioland

XLDnaute Nouveau
Re : macro qui colorie la ligne selectionné

merci pour ta réponse!! mais cette macro colorie simplement une seule cellule.
moi j'aimerai que la macro me colorie toute la ligne afin de la faire ressortir. Ma macro ressemble a ca.

Que faudrait il que je change:

mot = InputBox("Mot à rechercher ? ENTREZ : N°Qmos/ N°norme matiére / Groupe matiére")
If mot = "" Then Exit Sub

For feuille = 1 To Sheets.Count

Sheets(feuille).Select
Set trouvé1 = Cells.Find(What:=mot)
If Not trouvé1 Is Nothing Then

With trouvé1
.Activate
.Select
.Rows("4:4").Interior.ColorIndex = 3


End With

étiq:
If MsgBox("Suivant ?", 4) = vbNo Then Exit Sub
Set trouvé2 = Cells.FindNext(After:=ActiveCell)
Set trouvé3 = Cells.FindPrevious(After:=ActiveCell)

Do While trouvé2 <> trouvé1

With trouvé1
.Select
.Font.ColorIndex = 0
End With
With trouvé3
.Select
.Font.ColorIndex = 0
End With
With trouvé2
.Activate
.Select
.Rows("4:4").Interior.ColorIndex = 3


End With

GoTo étiq

Loop
End If
Next feuille

MsgBox "PLUS DE RESUSLTAT"

End Sub
 

phlaurent55

Nous a quittés en 2020
Repose en paix
Re : macro qui colorie la ligne selectionné

Re,
merci pour ta réponse!! mais cette macro colorie simplement une seule cellule.
cette ligne de code mettra toute la ligne en couleur rouge:
Rows(i).Interior.ColorIndex = 3

je t'ai également envoyé une réponse sur l'autre fil de discussion concernant la remise en couleur à l'état initial

mais je pense qu'il y a mieux et plus simple à faire ( par double-clic ou clic-droit)

à+
Philippe
 

yvioland

XLDnaute Nouveau
Re : macro qui colorie la ligne selectionné

je suis désolé mais sa ne marche pas j'ai reécrit mon programme comme ci dessous. il m'indique qu'il y'a plusieur erreur de synthaxe.


Sub Macro1()
'
' Macro1 Macro
' Macro enregistrée le 26/05/2011 par cmi
'Private Sub bouton recherche_Click()

mot = InputBox("Mot à rechercher ? (mot simple)")
If mot = "" Then Exit Sub

For feuille = 1 To Sheets.Count

Sheets(feuille).Select
Set trouvé1 = Cells.Find(What:=mot)
If Not trouvé1 Is Nothing Then

With trouvé1
.Activate
.Select
.Rows(i).Interior.ColorIndex = 3


End With

étiq:
If MsgBox("Suivant ?", 4) = vbNo Then Exit Sub
Set trouvé2 = Cells.FindNext(After:=ActiveCell)
Set trouvé3 = Cells.FindPrevious(After:=ActiveCell)

Do While trouvé2 <> trouvé1

With trouvé1
.Select
.Font.ColorIndex = 0
End With
With trouvé3
.Select
.Font.ColorIndex = 0
End With
With trouvé2
.Activate
.Select
.Rows(i).Interior.ColorIndex = 3


End With

GoTo étiq

Loop
End If
Next feuille

MsgBox "PLUS DE RESUSLTAT"

End Sub

'
 

Membres actuellement en ligne

Statistiques des forums

Discussions
312 677
Messages
2 090 825
Membres
104 677
dernier inscrit
soufiane12