I would like to return the numerical part of a string. I've looked through Stackoverflow but so far the code doesn't work for me - I think there's a simple function I could use here.
I want to return the numerical values in a string, and have them put into a specific cell.
I've tried Val
which doesn't work as the string is something like "This is 2"
and therefore it just returns a 0. I would want to return the value 2 into a specific cell.
Dim mytext As String
mytext = c 'where c is my string
Dim myChars() As char
myChars() = mytext.ToCharArray()
' Loop through the array testing if each is a digit
Dim ch As characters
For Each ch In myChars
If char.IsDigit(ch) Then
cell.Value = ch
End If
Next
This gives me a compile error - user-defined type not defined...
The code I've looked at doesn't seem to make sense - I know it should be pretty simple but I'm not sure I understand what is wrong!