Function GetNbr(str As String, mypattern As String, separateur As String) As String Dim i As Integer resul = "" i = 0 c = "" GetNbr = "" While i < Len(str) i = i + 1 c = Mid(str, i, 1) If c Like mypattern Then GetNbr = GetNbr + c ElseIf Len(GetNbr) > 0 Then If Mid(GetNbr, Len(GetNbr), 1) <> separateur Then GetNbr = GetNbr + separateur End If End If Wend End Function
Sub extraireValeursNumeriques_DansChaine() Dim i As Byte, Nb As Byte Dim Cible As String, Resultat As String Dim Nombre As Double Cible = "12,3azerty23,5 67" 'Pour que fonction Val puisse reconnaitre les décimales: Remplacement des 'virgules par des points Cible = Replace(Cible, ",", ".") 'Pour gérer deux nombres qui se suivent: remplacement des espaces 'par un caractère Alpha Cible = Replace(Cible, " ", "x") For i = 1 To Len(Cible) If IsNumeric(Mid(Cible, i, 1)) Then Nombre = Val(Mid(Cible, i, Len(Cible) - i + 1)) Nb = Nb + 1 Resultat = Resultat & Nombre & vbLf i = i + Len(Str(Nombre)) - 1 End If Next MsgBox "Il y a " & Nb & " valeurs numériques dans la cellule " & vbLf & Resultat End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionJ3 : "Thanks to find the credit memo regarding/the labour for your warranty claim ://10077 , 25, 1068"
et je voudrais
K3 : 10077/10425/10568
toto = "zzzzz22jgjgjj5jkjkjkkj8fffff" titi = toto resul = "" Do While Len(titi) > 0 Do While Not titi Like "#*" titi = Mid(titi, 2) If titi = "" Then Exit Do Loop If titi <> "" Then resul = resul & " " & Val(titi) Else Exit Do Do While titi Like "#*" titi = Mid(titi, 2) Loop Loop MsgBox resul
ton code m'a l'air de répondre à ma demande mais je n'arrive pas à l'adapter à mon besoin pour le tester vraiment : à savoir qu'il traite toutes les lignes de la colonne J et renvoi les nombres non pas dans un msgbox mais dans la colonne K...
et oui la relecture est importante mais on ne prend pas toujours le temps...quand on est dérangé toutes les 3 secondes c pas évident
Public Function ExtNum(ByVal vsCellContent As String, Optional ByRef vsSep As String = "/") As String Dim Match As Object With CreateObject("VbScript.Regexp") .Pattern = "\d+" .Global = True For Each Match In .Execute(vsCellContent) If LenB(ExtNum) Then ExtNum = ExtNum & vsSep End If ExtNum = ExtNum & Match.Value Next End With End Function