С регулярным выражением:
Function AnyPercentage(Text As String) As Integer
With CreateObject("VBScript.RegExp")
.Pattern = "[0-9]+\.[0-9]+\%"
AnyPercentage = "-1"
If .test(Text) Then
AnyPercentage = Replace(.Execute(Text)(0), "%", "")
End If
End With
End Function
Без регулярного выражения:
Sub GetPercentage()
Dim a
a = Split("Today's gain was 5.24% from yesterday%", "%")
Dim Hsl
If UBound(a) > 0 Then
Hsl = a(0)
a = Split(Hsl, " ")
r = UBound(a)
If IsNumeric(a(r)) Then
Hsl = a(r) & "%"
End If
End If
MsgBox Hsl
End Sub
В функции
Function GetPercentage(myVal as string) as string
Dim a
a = Split(myVal , "%")
Dim Hsl
If UBound(a) > 0 Then
Hsl = a(0)
a = Split(Hsl, " ")
r = UBound(a)
If IsNumeric(a(r)) Then
Hsl = a(r) & "%"
End If
End If
GetPercentage = Hsl
End Function