recherche paragraphe dans Textbox

  • Initiateur de la discussion Initiateur de la discussion Temjeh
  • Date de début Date de début

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 !

Temjeh

XLDnaute Accro
Bonjour et merci d'avance

J'importe du texte dans mon TextBox (ca va)
J'aimerais savoir si il y a un bout de code pour faire une recherche dans le TextBox de mon UserForm.

Exemple si il trouve 3 dans mon TextBox, il scroll ou met en première ligne le texte ou ce trouve le 3.

Merci beaucoup

Temjeh
 
Re : recherche paragraphe dans Textbox

Bonjour

J'ai trouvé ceci mais il met la valeur recherché dans la dernière ligne du textbox, pas la premère

Code:
With Me!TextBox2
    strSearch = InputBox("Enter text to find:")
    intWhere = InStr(.Value, strSearch)
    If intWhere Then
        .SetFocus
        .SelStart = intWhere - 1
        .SelLength = Len(strSearch)
    Else
        MsgBox "String not found."
    End If
 End With

Merci
 
Re : recherche paragraphe dans Textbox

Bonjour Temjeh,

Il faut décompter les renvois à la ligne vbLf :

Code:
With Me.TextBox2
    strSearch = InputBox("Enter text to find:")
    intWhere = InStr(Replace(.Value, vbLf, ""), strSearch)
    If intWhere Then
        .SetFocus
        .SelStart = intWhere - 1
        .SelLength = Len(strSearch)
    Else
        MsgBox "String not found."
    End If
 End With
A+
 
Re : recherche paragraphe dans Textbox

Re,

Il faut d'abord placer le curseur à la fin du texte :

Code:
With TextBox2
    strSearch = InputBox("Enter text to find:")
    intWhere = InStr(Replace(.Value, vbLf, ""), strSearch)
    If intWhere Then
        .SetFocus
        .SelStart = Len(.Value) 'curseur à la fin du texte
        .SelStart = intWhere - 1
        .SelLength = Len(strSearch)
    Else
        MsgBox "String not found."
    End If
 End With
Bien entendu si la sélection est dans les dernières lignes elle ne peut pas être en haut de la TextBox !

Fichier joint.

A+
 

Pièces jointes

- 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
19
Affichages
804
Réponses
3
Affichages
288
Réponses
41
Affichages
1 K
Réponses
23
Affichages
472
Retour