Sub RechercherMot()
Dim mot As String
mot = InputBox("Mot à rechercher ?")
If mot = "" Then Exit Sub
For Each c In Range("A1:E9") 'A adapter
If c.Value Like mot Then
c.Interior.ColorIndex = 3
c.MergeCells = False
End If
Next
End Sub
Bonsoir Eric C,Bonsoir le forum
Bonsoir cd
Avant toute chose, je t'invite ainsi que nombre de membres de ce forum, à prendre connaissance de la charte XLD dès lors que tu désires poster.
Regarde la pièce jointe 1058386
Une approche de ton problème :
VB:Sub RechercherMot() Dim mot As String mot = InputBox("Mot à rechercher ?") If mot = "" Then Exit Sub For Each c In Range("A1:E9") 'A adapter If c.Value Like mot Then c.Interior.ColorIndex = 3 c.MergeCells = False End If Next End Sub
Bonne soirée à toutes & à tous ET prenez bien soin de vous et des vôtres avec la pandémie qui n'a pas fini de faire parler d'elle.
Regarde la pièce jointe 1058387
Sub colorier(xplage As Range, xmot)
Dim xcell As Range, x, deb&, mot
Application.ScreenUpdating = False
xplage.Font.ColorIndex = xlColorIndexAutomatic
For Each xcell In xplage
mot = Trim(xmot) & " "
deb = 1
x = xcell.Value & " "
If Left(xcell, Len(mot)) = mot Then
xcell.Characters(1, Len(mot) - 1).Font.Color = RGB(255, 0, 0)
deb = Len(mot) + 1
End If
mot = " " & mot
Do
deb = InStr(deb, x, mot)
If deb > 0 Then
xcell.Characters(deb + 1, Len(mot) - 2).Font.Color = RGB(255, 0, 0)
deb = deb + Len(mot)
Else
Exit Do
End If
Loop
Next xcell
End Sub
Bonsoir,Bonsoir à tous,
Une macro générale pour colorier un mot dans une plage:
VB:Sub colorier(xplage As Range, xmot) Dim xcell As Range, x, deb&, mot Application.ScreenUpdating = False xplage.Font.ColorIndex = xlColorIndexAutomatic For Each xcell In xplage mot = Trim(xmot) & " " deb = 1 x = xcell.Value & " " If Left(xcell, Len(mot)) = mot Then xcell.Characters(1, Len(mot) - 1).Font.Color = RGB(255, 0, 0) deb = Len(mot) + 1 End If mot = " " & mot Do deb = InStr(deb, x, mot) If deb > 0 Then xcell.Characters(deb + 1, Len(mot) - 2).Font.Color = RGB(255, 0, 0) deb = deb + Len(mot) Else Exit Do End If Loop Next xcell End Sub
- xplage est la plage de cellules à traiter
- xmot est le mot à rechercher (une cellule, une variable ou une constante)
Voir son utilisation dans dans la macro test associée au bouton Hop!
edit : bonjour @Eric C
Bonjour,Bonsoir,
Merci beaucoup c'est vraiment ce que je voulais