Chaine de caractères

Bonjour,

Je travail sous Vba excel 2010

Je souhaite colorer les cellules d'une plage qui contiennent entre autre la valeur d'une textbox .

J'ai commencé ce code mais la fonction s’arrête a la première condition rencontré.

J'aimerai aussi que le code trouve la valeur de la textbox meme au milieu d'autres caractères.

Je suis vraiment bloqué...

Merci d'avance

Sub Macro1()
'
' Macro1 Macro
' Macro enregistrée le 04/06/2014 par Raphael

Dim strChaine As String
Dim Cell As Range
Dim Zone As Range

strChaine = textbox2.value
Set Zone = Range("A1:Z30")
Set rngTrouve = Zone.Cells.Find(what:=strChaine)

If rngTrouve Is Nothing Then
MsgBox "Pas trouvé"
Else
For Each Cell In Zone
 If Cells.Find(what:=strChaine).Activate  Then
ActiveCell.Interior.ColorIndex = 5
End If
Next Cell
End If

Set rngTrouve = Nothing
End Sub

Bonsoir,

une proposition de modification de ta macro

Sub Macro1()
'
' Macro1 Macro
' Macro enregistrée le 04/06/2014 par Raphael

    Dim strChaine As String
    Dim Cell As Range
    Dim Zone As Range

    strChaine = textbox2.Value

    Set Zone = Range("A1:Z30")
    ctr = 0

    Set c = Zone.Find(strChaine, Lookat:=xlPart)
    If Not c Is Nothing Then
        ctr = ctr + 1
        firstAddress = c.Address
        Do
            c.Interior.ColorIndex = 5
            Set c = Zone.FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If

If ctr = 0 Then MsgBox "Pas trouvé"

End Sub

Merci beaucoup

Rechercher des sujets similaires à "chaine caracteres"