hello
Can someone pls tell me how to get only numbers from a string?
exp:
string = "ABC129" or "A12CD" or any other combinations so i cant simply use left or right funtion...
and i want to get only "129" or "12" in my output sting2
thx
hello
Can someone pls tell me how to get only numbers from a string?
exp:
string = "ABC129" or "A12CD" or any other combinations so i cant simply use left or right funtion...
and i want to get only "129" or "12" in my output sting2
thx
Hello Sasolini,
You need to strip the numbers from the string and build a new string of only number. This macro code will do that for you.
Macro Code:
Public Function NumbersOnly(ByVal String_To_Convert As String) As String
Dim I As Integer
Dim NumStr As String
TestChr As Integer
For I = 1 To Len(String_To_Convert)
TestChr = Asc(Mid(String_To_Convert, I, 1))
If TestChr > 47 And TestChr < 58 Then
NumStr = NumStr & Chr(TestChr)
End If
Next I
NumbersOnly = NumStr
End Function
Using the Macro:
NumberString = NumberOnly("ABC123XYZ06SLF")
NumberString will contain the string "12306"
Hope this helps,
Leith Ross
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks