Chercher dans Range de cellule

Hello à tous,

J'utilise ce petit bout de code (en Feuil1) pour lancer un lien hypertext (en Feuil2) lors d'un double clic dans une liste déroulante (en Feuil1).

Petit soucis la recherche dans Feuil2 ne fonctionne que dans la colonne "A" ... et j'ai épuisé mes (toutes petites) connaissance en VBA.

Je pense que cela vient de cette ligne : Lastrow = Sheets("Feuil2").Cells(Rows.Count, "A").End(xlUp).Row

Mais je ne sais pas comment lui dire de chercher dans toutes la Feuil2.

Une idée ?

Voici mon code :

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

On Error GoTo getout:

Application.ScreenUpdating = False

Dim c As Range

Dim ans As String

Dim Lastrow As Long

ans = ActiveCell.Value

Lastrow = Sheets("Feuil2").Cells(Rows.Count, "A").End(xlUp).Row

For Each c In Sheets("Feuil2").Range("A1:AA" & Lastrow)

If c.Value = ans Then Sheets("Feuil2").Range(c.Address).Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True: Exit Sub

Next

Application.ScreenUpdating = True

getout:

End Sub

7test.xlsm (38.15 Ko)

MERCI

Nico

••••ˇˇˇˇ

Bonsoir,

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim c As Range, ans As String, Lastrow As Long
    On Error GoTo getout
    ans = Target.Value
    Lastrow = Sheets("Feuil2").Range("A1").SpecialCells(xlCellTypeLastCell).Row
    For Each c In Sheets("Feuil2").Range("A1:AA" & Lastrow)
        If c.Value = ans Then
            Sheets("Feuil2").Range(c.Address).Hyperlinks(1).Follow False, True
            Exit Sub
        End If
    Next c
getout:
End Sub

Un énorme merci !!

Ca fonctionne nickel !

Rechercher des sujets similaires à "chercher range"