Optimisation Fonction Recherche

Bonsoir à tous,

J'aimerais optimiser une fonction que j'ai développée pour un de mes tableurs.

Cette fonction me permet d'effectuer une recherche de prénoms et noms dans un annuaire de contact important :

Private Sub TextBox1_Change()

Application.ScreenUpdating = False

Range("A5:A999").Interior.ColorIndex = 3

Range("B5:B999").Interior.ColorIndex = 3

Range("C5:C999").Interior.ColorIndex = 3

Range("D5:D999").Interior.ColorIndex = 3

Range("E5:E999").Interior.ColorIndex = 3

Range("F5:F999").Interior.ColorIndex = 3

Range("G5:G999").Interior.ColorIndex = 3

Range("H5:H999").Interior.ColorIndex = 3

Range("I5:I999").Interior.ColorIndex = 3

Range("J5:J999").Interior.ColorIndex = 3

Range("K5:K999").Interior.ColorIndex = 3

Range("L5:L999").Interior.ColorIndex = 3

Range("M5:M999").Interior.ColorIndex = 3

Range("N5:N999").Interior.ColorIndex = 3

Range("O5:O999").Interior.ColorIndex = 3

Range("P5:P999").Interior.ColorIndex = 3

Range("Q5:Q999").Interior.ColorIndex = 3

Range("R5:R999").Interior.ColorIndex = 3

If TextBox1 <> "" Then

For ligne = 5 To 999

If Cells(ligne, 3) Like "*" & TextBox1 & "*" Then

Cells(ligne, 1).Interior.ColorIndex = 43

Cells(ligne, 2).Interior.ColorIndex = 43

Cells(ligne, 3).Interior.ColorIndex = 43

Cells(ligne, 4).Interior.ColorIndex = 43

Cells(ligne, 5).Interior.ColorIndex = 43

Cells(ligne, 6).Interior.ColorIndex = 43

Cells(ligne, 7).Interior.ColorIndex = 43

Cells(ligne, 8).Interior.ColorIndex = 43

Cells(ligne, 9).Interior.ColorIndex = 43

Cells(ligne, 10).Interior.ColorIndex = 43

Cells(ligne, 11).Interior.ColorIndex = 43

Cells(ligne, 12).Interior.ColorIndex = 43

Cells(ligne, 13).Interior.ColorIndex = 43

Cells(ligne, 14).Interior.ColorIndex = 43

Cells(ligne, 15).Interior.ColorIndex = 43

Cells(ligne, 16).Interior.ColorIndex = 43

Cells(ligne, 17).Interior.ColorIndex = 43

Cells(ligne, 18).Interior.ColorIndex = 43

ElseIf Cells(ligne, 4) Like "*" & TextBox1 & "*" Then

Cells(ligne, 1).Interior.ColorIndex = 43

Cells(ligne, 2).Interior.ColorIndex = 43

Cells(ligne, 3).Interior.ColorIndex = 43

Cells(ligne, 4).Interior.ColorIndex = 43

Cells(ligne, 5).Interior.ColorIndex = 43

Cells(ligne, 6).Interior.ColorIndex = 43

Cells(ligne, 7).Interior.ColorIndex = 43

Cells(ligne, 8).Interior.ColorIndex = 43

Cells(ligne, 9).Interior.ColorIndex = 43

Cells(ligne, 10).Interior.ColorIndex = 43

Cells(ligne, 11).Interior.ColorIndex = 43

Cells(ligne, 12).Interior.ColorIndex = 43

Cells(ligne, 13).Interior.ColorIndex = 43

Cells(ligne, 14).Interior.ColorIndex = 43

Cells(ligne, 15).Interior.ColorIndex = 43

Cells(ligne, 16).Interior.ColorIndex = 43

Cells(ligne, 17).Interior.ColorIndex = 43

Cells(ligne, 18).Interior.ColorIndex = 43

End If

Next

End If

End Sub

1 - Comment optimiser le surlignement : mes données commencent à partir de la ligne 5 ?

J'aimerais que le surlignement se réalise à partir de la ligne 5 pour les lignes qui ont des contenus.

2 - Idem pour le reset du surlignement

3 - Mon code ne permet pas une recherche optimale ...

Pour trouver le prénom et/ou le nom, il me faut écrire dans le bon ordre les lettres avec les majuscules ou minuscules :

Pascal = OK -> pascal = NOK / DURANT = OK -> Durant = NOK

4 - Pour finir j'aimerais lors de la recherche que le tableur conserve seulement la ou les lignes contant les caractéres écrits dans le textbox :

Pas (Pascal) = toutes les lignes contenant ces trois lettres apparaissent. Les autres lignes disparaissent.

Voila, en espérant que mes demandes sont compréhensibles.

Merci d'avance pour votre aide.

Bon courage à ceux qui prendront le temps de répondre à ce sujet.

Cordialement

Nico

Bonjour,

Bonjour,

Ci-joint le fichier tronqué et modifié pour respecter la loi RGPD en espérant que cela vous suffit.

Cordialement

Nico

7f-c-v6.xlsm (144.57 Ko)

Bon, je me suis sorti les doigts de là ou vous le pensé.

J'ai réussi à coder toutes mes fonctionnalités.

Pour ceux que ça intéresse je peux partager mes modifications.

Merci pour l'aide ....

Bonsoir,

Veuillez m'excuser de m'incruster alors que le sujet est résolu...

Votre fichier en retour :

21f-c-v1-lrd.xlsm (176.07 Ko)

J'ai transformé votre plage de donnée en tableau structuré, je gère le textebox1 au fur et à mesure de l'entrée des caractères de recherche, en fonction je filtre la colonne Nom afin de ne laisser que ceux qui corresponde au début de recherche.

Du coup nul besoin de mettre en couleur les lignes, puisque seules celles correspondant à la recherche sont affichées.

@ bientôt

LouReeD

Bonsoir LouReed,

Merci pour l'optimisation.

Je vais de suite faire l' update.

++

Rechercher des sujets similaires à "optimisation fonction recherche"