ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   extract string (https://www.excelbanter.com/excel-programming/300029-extract-string.html)

dreamer[_17_]

extract string
 
I have a string that looks like this:

15;18;22;25

or like this

2;89

How can I extract it so it returns only the numbers from the string.
So in the first case it would be 15 18 22 25 etc..

--
Message posted from http://www.ExcelForum.com


Norman Jones

extract string
 
Hi Dreamer,

Sub Tester()

Dim sStr As String
Dim i As Long
Dim v As Variant

sStr = "15;18;22;25"

v = Split(sStr, ";")

For i = LBound(v) To UBound(v)
MsgBox v(i)
Next i

End Sub

I believe that the Split function was added in xl2. If you are using an
earlier version then you could use the following function supplied by Tom
Ogilvy:

Function Split97(sStr As Variant, sdelim As String) As Variant
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function

---
Regards,
Norman


"dreamer " wrote in message
...
I have a string that looks like this:

15;18;22;25

or like this

2;89

How can I extract it so it returns only the numbers from the string.
So in the first case it would be 15 18 22 25 etc...


---
Message posted from http://www.ExcelForum.com/




Bob Phillips[_6_]

extract string
 
Just use DataText to Columns with a delimiter of ;.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dreamer " wrote in message
...
I have a string that looks like this:

15;18;22;25

or like this

2;89

How can I extract it so it returns only the numbers from the string.
So in the first case it would be 15 18 22 25 etc...


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com