Hello SaqibHi, what a pleasant surprise.....long time.
... I made it so the result goes on a separate sheet Result.No problem. I can handle that.
In your sample the first item 13 is at position 17 not 18 !!!Thanks for the correction
Here is the code
Let me knowAll good
Sub TestFunction()
Dim strInString As String
Dim lngNumbers() As Long
Dim lngElement As Long
strInString = " Me.Table13LayoutPanel1.Con
lngNumbers = fncNumbersFromString(strIn
For lngElement = 0 To UBound(lngNumbers, 2)
Debug.Print "Number " & lngNumbers(0, lngElement) & " was found at position " & lngNumbers(1, lngElement)
Next lngElement
End Sub
Function fncNumbersFromString(strSt
Dim lngNumberArray() As Long
Dim lngCharPos As Long
ReDim lngNumberArray(1, 0)
For lngCharPos = 1 To Len(strString)
If IsNumeric(Mid(strString, lngCharPos, 1)) Then
lngNumberArray(0, UBound(lngNumberArray(), 2)) = CLng(Mid(strString, lngCharPos, 1)) ' the number
lngNumberArray(1, UBound(lngNumberArray(), 2)) = lngCharPos 'the position
ReDim Preserve lngNumberArray(1, UBound(lngNumberArray, 2) + 1)
End If
Next lngCharPos
If UBound(lngNumberArray, 2) > 0 Then
'At least 1 number was found, remove empty array
ReDim Preserve lngNumberArray(1, UBound(lngNumberArray, 2) - 1)
Else
'no numbers were found in string, no need to redimension
' do nothing
End If
fncNumbersFromString = lngNumberArray
End Function