1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| Sub recherche()
Dim wk As Workbook
Dim c As Range ' Resultat de la recherche
Dim mot As String, sResult()
mot = InputBox("saisissez la ville")
Dim f As Worksheet 'Feuille dans laquelle effectuer la rechercher
'Application.ScreenUpdating = False
'Ouverture du classeur :
'Set wk = ActiveWorkbook
Set wk = Workbooks.Open("file://localhost/users/sebneb/Desktop/liste.xls")
'Effectue recherche dans 1° feuille du classser
'Sheets(1).Visible = False
With wk.Sheets(1).Range("b:b")
Set c = .Find(What:=mot, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not c Is Nothing Then
firstAddress = c.Address
Do
i = i + 1
ReDim Preserve sResult(i)
sResult(i) = c.Address
'sResult = sResult & c.Value & vbCrLf
'sResult = sResult & c.Value & vbLf
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
If UBound(sResult) > 0 Then
For i = 1 To UBound(sResult)
MsgBox Cells(Range(sResult(i)).Row, 1)
Next
ElseIf sResult(1) <> "" Then
MsgBox sResult(1)
Else
MsgBox mot & " Introuvable"
End If
' Load Recherche 'recherche correspond sur cette ligne au nom de la userform1
' Recherche.Show ' meme chose recherche...
'wk.Close False ' Fermetur de classeur sans sauvegarde...
Application.ScreenUpdating = True 'Réactive l'affichage
End Sub |
Partager