Je ferais comme suit :
Sub test()
MsgBox get_Somme("coca 2€;fanta 3€", "2 coca;5 fanta")
End Sub
Function get_Somme(str_valeurs As String, str_choix As String) As String
'on parse les entrées pour faire le total
'entrées : str_valeurs "coca 2€;fanta 3€;..."
' str_choix "3 coca; 2 fanta;..."
'sortie : "coca : 6€;fanta 6€;...."
Const Ct_Csv_Sep = ";" 'separateur du champ csv
Dim Tab_Valeurs, Tab_Choix
Dim My_Valeurs, My_Choix As String
'on vire les espaces et les euros
My_Valeurs = Replace(Trim(Replace(str_valeurs, "€", "")), ":", "")
My_Choix = Replace(Trim(Replace(str_choix, "€", "")), ":", "")
'on splitte l'entrée et les choix
Tab_Valeurs = Split(My_Valeurs, Ct_Csv_Sep, -1, vbTextCompare)
Tab_Choix = Split(My_Choix, Ct_Csv_Sep, -1, vbTextCompare)
'on a ainsi deux tableaux avec les deux strings
Dim My_Result, My_Entree, My_Boisson As String
Dim My_Nombre, My_Prix As Integer
Dim int_I, Int_J, Int_k As Integer
For int_I = 0 To UBound(Tab_Choix)
My_Entree = Tab_Choix(int_I)
Int_k = InStr(1, My_Entree, " ", vbTextCompare)
If Int_k > 1 Then
My_Nombre = Left(My_Entree, Int_k - 1)
My_Boisson = Right(My_Entree, Len(My_Entree) - Int_k)
For Int_J = 0 To UBound(Tab_Valeurs)
If InStr(1, Tab_Valeurs(Int_J), My_Boisson) Then
'on est sur le bon prix
Int_k = InStr(1, Tab_Valeurs(Int_J), " ", vbTextCompare)
My_Result = My_Result & My_Nombre & " " & My_Boisson & _
" : " & CStr(My_Nombre * Right(Tab_Valeurs(Int_J), Len(Tab_Valeurs(Int_J)) - Int_k)) & " €" & Ct_Csv_Sep
End If
Next Int_J
End If
Next int_I
get_Somme = My_Result
End Function
Irem