I am really new to excel VBA and struggling to write a function which can extract a decimal number from an alphanumerical string like 1.25/g or 23.5g etc. The decimal number will always be in front.
I found some solutions to the problem but they don't apply to decimal numbers.
I found a solution which works for some strings but doesn't work for all. I have posted the function below. Its returning 1.2 g as 1, but works for a lot of other numbers.
Thanks in advance.
Public Function first_try(a) As Double
Dim i As Long
For i = 1 To Len(a)
If IsNumeric(Mid(a, i, 1)) Then
first_try = Val(Mid(a, i))
Exit For
End If
Next i
Debug.Print firt_try
End Function