Bonjour guillaumeplougoulm , à tous ,
Une autre fonction personnalisée VBA à trois arguments : =TitreNomPrenom(monTexte, Lequel, Quoi) où :
- monTexte est le texte source
- Lequel est le rang de l’individu dont on veut extraire les informations (1 => première personne, 2 => 2ème personne, N => Nème personne...)
- Quoi est l'information à extraire (1 => titre, 2 => Nom, 3 => Prénom)
Le code de la fonction dans module1:
Function TitreNomPrenom$(monTexte$, Lequel&, Quoi&)
Dim x$, nbr&, t, res, y, i&, j&, k&, n&
If Quoi < 1 Or Quoi > 3 Then Exit Function
x = Application.Trim(Replace(Replace(monTexte, "M. ", Chr(255) & "M. "), "Mme ", Chr(255) & "Mme "))
If x = "" Then Exit Function
nbr = Len(x) - Len(Replace(x, Chr(255), ""))
If nbr < 1 Then Exit Function
If Lequel < 1 Or Lequel > nbr Then Exit Function
t = Split(Trim(x), Chr(255)): ReDim res(1 To 3 * nbr)
For i = 1 To UBound(t)
y = Split(Trim(t(i)))
res(3 * n + 1) = y(0)
For j = UBound(y) To 1 Step -1
If UCase(y(j)) = y(j) Then Exit For
Next j
If j >= 1 Then
For k = 1 To j: res(3 * n + 2) = res(3 * n + 2) & " " & y(k): Next k
For k = j + 1 To UBound(y): res(3 * n + 3) = res(3 * n + 3) & " " & y(k): Next k
res(3 * n + 2) = Trim(res(3 * n + 2)): res(3 * n + 3) = Trim(res(3 * n + 3))
End If
n = n + 1
Next i
TitreNomPrenom = res(3 * (Lequel - 1) + Quoi)
End Function