Sub test()
chaine = "year(datepart(sousc.D_VALO))=2021 and month(datepart(sousc.D_VALO))=12 and day(datepart(sousc.D_VALO))=31"
nb = GetNumOnText(chaine)
MsgBox nb(0) & vbCrLf & nb(1) & vbCrLf & nb(2)
End Sub
Function GetNumOnText(ByVal T As String, Optional Index As Long = -1, Optional ConvertNum As Boolean = False)
Dim I&, TbL
If ConvertNum Then T = Replace(T, ",", ".")
I = 1
For I = I To Len(T)
If Mid(T, I, 1) Like "[!0-9|.|,]" Then Mid(T, I, 1) = " "
If Mid(T, I, 1) Like "[.|,]" Then If Mid(T, I - IIf(I > 1, 1, 0), 1) Like "[!0-9|]" Or Mid(T, I, 1) Like "[!0-9,.]" Then Mid(T, I, 1) = " "
Next
With Application
If TypeName(.Caller) = "Range" Then
'si la fonction a été appelée par une formule
If Index = -1 Then 'si pas d'index demandé c'est une matricielle
If .ThisCell.Offset(1).Formula = .ThisCell.Formula Then 'si matricielle verticale
GetNumOnText = .Transpose(Split(Application.Trim(T) & Application.Rept(" ", 1000)))
Else
GetNumOnText = Split(Application.Trim(T) & Application.Rept(" ", 1000), " ") ' si matricielle horizontal
End If
Else
'si index demandé et si le text n'est pas vide return de l'item demandé
If T = "" Then GetNumOnText = "" Else GetNumOnText = Split(Application.Trim(T) & Application.Rept(" ", 1000), " ")(Index)
End If
Else
' si la fonction a été appelée par VBA
If Index = -1 Then
GetNumOnText = Split(Application.Trim(T), " ")
Else
GetNumOnText = Split(Application.Trim(T), " ")(Index)
End If
End If
End With
End Function