TWiesendanger
9/7/2018 - 11:03 AM

Keep Only 2 Digits of String in another String

Im Angegebenen String wird nach einem String gesucht und 2 Stellen nach rechts beibehalten.

Sub Main()
	Dim st As String, Out As String
    st = "hfskfhjsdfshjJ*123456"
    Out = RetDigits(st)
    MsgBox (Out)
End Sub
Public Function RetDigits(sIN As String) As String
    Dim lookFor As String, v As String
    lookFor = "J*"
    RetDigits = ""
    If InStr(sIN, lookFor) = 0 Then Exit Function
    ary = Split(sIN, lookFor)
    If Len(ary(1)) < 2 Then Exit Function
    RetDigits = Left(ary(1), 2)
End Function