Bonjour à tous,
J'ai une base d'articleS sur excel avec une macro de recherche et de lien hypertexte que j'utilise depuis 4 ans. mais j'ai rajouté pas mal d'article et de colonnes; et l'exécution de la macro devient de plus en plus longue à s'exécute. J'ai regardé le code VBA mais je ne suis pas un expert. Je pense que la recherche s'effectue sur toute la feuille nommé base et je n'ai besoin que de la recherche sur la colonne A,B et C. d'ou peut être son ralentissement. Peut on modifié ou amelioré cette macro pour rendre l'exécution plus rapide. ( l'exemple comporte 10 articles en réalité j'ai 2400 articles sur la feuille base)
Merci de votre aide et bonne journée
Fred
Feuille recherche:
Sub Recherche_de_mot()
Application.ScreenUpdating = False
Dim reponse As String
reponse = InputBox("RECHERCHE", "ENTRE MER ET PLAGE")
Range("A12:IV65536").Clear
If Len(reponse) > 0 Then
Call recherche(reponse)
End If
Application.ScreenUpdating = True
End Sub
Feuille base:
Sub recherche(mot)
Application.ScreenUpdating = False
Dim ligne As Long
Dim wR As Worksheet
Dim wB As Worksheet
Dim firstAddress As String
Dim c As Range
Dim trouve As Boolean
Dim x As Long
Dim iCol As Long
Dim cLink As Range
Set wR = Sheets("recherche")
If wR Is Nothing Then
MsgBox "La feuille 'recherche' n'existe pas!"
Exit Sub
End If
Set wB = Sheets("base")
If wB Is Nothing Then
MsgBox "La feuille 'base' n'existe pas!"
Exit Sub
End If
ligne = 12
wR.Range("A12:IV65536").Clear
With wB.Cells
Set c = .Find(mot, LookIn:=xlValues, lookat:=xlPart)
If Not c Is Nothing Then
firstAddress = c.Address
Do
wB.Rows(c.Row).Copy Destination:=wR.Cells(ligne, 1)
'création des liens hypertexte
For iCol = 2 To 23
Set cLink = wR.Cells(ligne, iCol)
If Len(cLink.Text) > 0 Then
cLink.Hyperlinks.Add cLink, "", wB.Name & "!$" & Chr(iCol + 64) & "$" & c.Row, , cLink.Text
End If
Next
ligne = ligne + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
trouve = True
End If
End With
x = wR.Range("B65536").End(xlUp).Row
If x > 14 Then
Dim n As Long
For n = x To 15 Step -1
For m = 1 To 7
xx = xx & wR.Cells(n, m)
yy = yy & wR.Cells(n - 1, m)
Next m
If yy = xx Then wR.Rows(n).Delete
xx = ""
yy = ""
Next
End If
If Not trouve Then MsgBox ("Le mot " & mot & " n'a pas été trouvé dans ce fichier")
Application.ScreenUpdating = True