Excel / VBA - A Trova ricerca con ritorno multiplo

Una semplice ricerca Trova restituisce che restituirà la prima coordinata.
  • In alcune situazioni è necessario conoscere tutti i dettagli delle occorrenze rilevate.
  • Questo è ottenuto con la funzione sottostante.

In un modulo pubblico

 'Retourne toutes les adresses trouvées dans la recherche' WkbN = nom di classeur, avec cette donnée la fonction peut être mise dans un xla 'WksN = nom de la feuille' Plage = coordonnées de la plage à parcourir. 'Retour dans le tableau donner en argument. Funzione RechFind (ByVal Cle As String, ByVal WkbN As String, ByVal WksN As String, ByVal Plage As String, ByRef TBadress () As Variant) As Long Dim Cherche, Ix As Long, PrAddress With Workbooks (WkbN) .Sheets (WksN) .Range (Plage) Imposta Cherche = .Find (Cle) Se Not Cherche non è nulla ThenPrAddress = Cherche.Address Do ReDim Preserva TBadress (Ix) TBadress (Ix) = Cherche.Address Imposta Cherche = .FindNext (Cherche) Ix = Ix + 1 Loop While Not Cherche Is Nothing e Cherche.Address PrAddress End If End con 'nombre d'occurrence (s) trouvée (s), Retour 0 si aucune occurrence RechFind = Ix Set Cherche = Nothing' Libére la mémoire occupée par l ' Objet. Fine Funzione 

Aggiungi a una cartella di lavoro Xla.

Utilizzando una macro

 Sub RechMulti () Dim R As Long, TB () Dim i As Intero R = RechFind ("12 *", ThisWorkbook.Name, "Feuil1", "B1: B500", TB ()) Se R> 0 Then For i = 0 A R - 1 'ou ubound (TB)' Fogli di esempio ("Feuil1"). Celle (i + 4, 5) = Intervallo (TB (i)). Riga Avanti e Fine Se Fine Sottotitolo 

Utilizzando un pulsante di chiamata

 Private Sub CommandButton1_Click () Dim R As Long, TB () Dim i As Intero Range ("E4: E20"). ClearContents R = RechFind (Range ("E2"), ThisWorkbook.Name, ActiveSheet.Name, Range ("B1 : B500 "). Indirizzo, TB ()) Se R> 0 Then For i = 0 To R - 1 'ou ubound (TB)' Fogli di esempio (" Feuil1 "). Cells (i + 4, 5) = Intervallo ( TB (i)). Riga Successivo o Fine Se Fine Sott 

Scaricare

Scarica la cartella di lavoro del test: qui.

Articolo Precedente Articolo Successivo

I Migliori Consigli