I have a custom function that was created to extract integers from a simple 11 character string that was alphanumeric with a hyphen. I need to modify or create a new custom function that can extract integers (with hyphens in some instances). The new string is variable in length and the integers I need to extract are on the left side of a vertical slash (vertical bar). The custom function I am currently using is posted below. If any one can help with the modification needed or script new code for the new string I am dealing with I would be very grateful.
Function GetNum(MyInput As String) Dim i As Integer Dim j As Integer Dim NumOnly As String 'Count total strings of Input For i = Len(MyInput) To 1 Step -1 If IsNumeric(Mid(MyInput, i, 1)) Then j = j + 1 NumOnly = Mid(MyInput, i, 1) & NumOnly End If If j = 1 Then NumOnly = CInt(Mid(NumOnly, 1, 1)) Next i GetNum = NumOnly End Function
Here is an example of the old string and new string:
Old String: ABC-1234567
New string 1: 1234567-99 | TEXT MORETEXT EXTENDEDTEXT - 23.8 XX YYYY 16:9
New string 2: 1234567 | BLAH BLAH EXTENDEDBLAH XYZ 123