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
|
Sub RemplirtabResultats()
Dim tabCriteres() As Variant
Dim tabCible() As Variant
Dim tabResultats() As Variant
Dim i As Long, j As Long, k As Long
Dim tabCle As String
Dim strVal As String
strVal = "Beta1"
' Alimentation des tableaux (pour le test)
tabCible = Range("A2:B9").Value ' Exemple de plage pour tabCible
tabCriteres = Range("D2:E7").Value
ReDim tabResultats(1 To UBound(tabCible, 1), 1 To 2)
' Copier la 1ère colonne de tabCible dans la 1ère colonne de tabResultats
For i = 1 To UBound(tabCible, 1)
tabResultats(i, 1) = tabCible(i, 1)
Next i
' Remplir la 2ème colonne de tabResultats
For i = 1 To UBound(tabCriteres, 1)
If tabCriteres(i, 1) = strVal Then
tabCle = tabCriteres(i, 2)
For j = 1 To UBound(tabCible, 1)
' Est présent ?
If InStr(tabCible(j, 2), tabCle) > 0 Then _
tabResultats(j, 2) = tabResultats(j, 2) & tabCle
Next j
End If
Next i
' Écrire les résultats dans une plage (pour le test)
Range("G2").Resize(UBound(tabResultats, 1), UBound(tabResultats, 2)).Value = tabResultats
End Sub |
Partager