Function FindAll(ByVal sText As String, ByRef oSht As Worksheet, ByRef sRange As String, ByRef arMatches() As String) As Boolean ' -------------------------------------------------------------------------------------------------------------- ' FindAll - To find all instances of the1 given string and return the row numbers. ' If there are not any matches the function will return false ' -------------------------------------------------------------------------------------------------------------- On Error GoTo Err_Trap Dim rFnd As Range ' Range Object Dim iArr As Integer ' Counter for Array Dim rFirstAddress ' Address of the First Find ' ----------------- ' Clear the Array ' ----------------- Erase arMatches Set rFnd = oSht.Range(sRange).Find(what:=sText, LookIn:=xlValues, lookAt:=xlPart) If Not rFnd Is Nothing Then rFirstAddress = rFnd.Address Do Until rFnd Is Nothing iArr = iArr + 1 ReDim Preserve arMatches(iArr) arMatches(iArr) = rFnd.Row 'rFnd.Address pour adresse complete ' rFnd.Row Pour N° de ligne Set rFnd = oSht.Range(sRange).FindNext(rFnd) If rFnd.Address = rFirstAddress Then Exit Do ' Do not allow wrapped search Loop FindAll = True Else ' ---------------------- ' No Value is Found ' ---------------------- FindAll = False End If ' ----------------------- ' Error Handling ' ----------------------- Err_Trap: If Err <> 0 Then MsgBox Err.Number & " " & Err.Description, vbInformation, "Find All" Err.Clear FindAll = False Exit Function End If End Function
Sub Exemple_util_Findall() Dim arTemp() As String 'variable tableau pour la fonction Findall Dim ValCherchee as string ValCherchee="test" Dim Nom_Feuil as string Nom_Feuil = "Feuil1" '--------------------------------------------------------------- bFound = FindAll(ValCherchee, Sheets(Nom_Feuil), ma_plage, arTemp()) '--------------------------------------------------------------- If bFound = True Then Debug.Print "Nb occurences : " & UBound(arTemp) For X = 1 To UBound(arTemp) debug.print arTemp(X) Next End If End sub
8 juil. 2014 à 09:48
Merci pour ton réponse :)
Modifié par jordane45 le 8/07/2014 à 10:20
Il faut juste modifier la SUB d'exemple pour la mettre dans ton Private Sub ComboBox1_Change() _change (et ajuster quelques variables)
un truc du genre :