Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Parsing a String to get Numbers


if anyone can provide me with a function that can parse a string t
retrieve numbers, numbers including decimals etc that would b
appreciated. I.E. "This is my string 0.000

--
nabukhala
-----------------------------------------------------------------------
nabukhalaf's Profile: http://www.excelforum.com/member.php...fo&userid=1504
View this thread: http://www.excelforum.com/showthread.php?threadid=26658

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Parsing a String to get Numbers

Already did -- but here it is again.

Sub Tester5()
Dim sString As String, sStr As String
Dim i As Long, sChr As String
sString = "This is my string 0.000"
For i = 1 To Len(sString)
sChr = Mid(sString, i, 1)
If IsNumeric(sChr) Or sChr = "." Then
sStr = sStr & sChr
End If
Next
MsgBox sStr

End Sub

gave me 0.000

--
Regards,
Tom Ogilvy


"nabukhalaf" wrote in message
...

if anyone can provide me with a function that can parse a string to
retrieve numbers, numbers including decimals etc that would be
appreciated. I.E. "This is my string 0.000"


--
nabukhalaf
------------------------------------------------------------------------
nabukhalaf's Profile:

http://www.excelforum.com/member.php...o&userid=15040
View this thread: http://www.excelforum.com/showthread...hreadid=266583



  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Parsing a String to get Numbers

Hi

I've rewritten Tom's Sub as a function

Function MyNum(sString As String) As Double
Dim sStr As String
Dim i As Long, sChr As String

For i = 1 To Len(sString)
sChr = Mid(sString, i, 1)
If IsNumeric(sChr) Or sChr = "." Then
sStr = sStr & sChr
End If
Next
MyNum = sStr
End Function

Copy this into a VB Module, then type +mynum(cellref)and
copy down

Regards
Peter
-----Original Message-----
Already did -- but here it is again.

Sub Tester5()
Dim sString As String, sStr As String
Dim i As Long, sChr As String
sString = "This is my string 0.000"
For i = 1 To Len(sString)
sChr = Mid(sString, i, 1)
If IsNumeric(sChr) Or sChr = "." Then
sStr = sStr & sChr
End If
Next
MsgBox sStr

End Sub

gave me 0.000

--
Regards,
Tom Ogilvy


"nabukhalaf"

wrote in message
...

if anyone can provide me with a function that can parse

a string to
retrieve numbers, numbers including decimals etc that

would be
appreciated. I.E. "This is my string 0.000"


--
nabukhalaf
--------------------------------------------------------

----------------
nabukhalaf's Profile:

http://www.excelforum.com/member.php?

action=getinfo&userid=15040
View this thread:

http://www.excelforum.com/showthread...hreadid=266583



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Parsing a String to get Numbers

Do you suppose one needs to be concerned with a string like

5 apples and 6 oranges

Your code would give 56, which isn't in the original string.

To eliminate that, you would have to set a flag that exits the loop when you
hit a non-number.

Sub Tester5()
Dim sString As String, sStr As String
Dim i As Long, sChr As String
Dim HaveDigits As Boolean

sString = "This is my string 0.000"
HaveDigits = False
For i = 1 To Len(sString)
sChr = Mid(sString, i, 1)
If IsNumeric(sChr) Or sChr = "." Then
sStr = sStr & sChr
HaveDigits = True
ElseIf HaveDigits Then
Exit For
End If
Next
MsgBox sStr
End Sub

On Tue, 5 Oct 2004 15:16:43 -0400, "Tom Ogilvy" wrote:

Already did -- but here it is again.

Sub Tester5()
Dim sString As String, sStr As String
Dim i As Long, sChr As String
sString = "This is my string 0.000"
For i = 1 To Len(sString)
sChr = Mid(sString, i, 1)
If IsNumeric(sChr) Or sChr = "." Then
sStr = sStr & sChr
End If
Next
MsgBox sStr

End Sub

gave me 0.000


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Parsing a String to get Numbers

Do you suppose one needs to be concerned with a string like
If your seriously asking a question, I suppose we could imagine all kinds of
situations, but the example provided was a single number embedded in a
string; so while I considered the problem of which you speak, I didn't
address it. Even if two or more number sequences were possible, the OP gave
no indication which should be extracted - however, your modification
certainly presents an approach to dealing with the problem.

--
Regards,
Tom Ogilvy




"Myrna Larson" wrote in message
...
Do you suppose one needs to be concerned with a string like

5 apples and 6 oranges

Your code would give 56, which isn't in the original string.

To eliminate that, you would have to set a flag that exits the loop when

you
hit a non-number.

Sub Tester5()
Dim sString As String, sStr As String
Dim i As Long, sChr As String
Dim HaveDigits As Boolean

sString = "This is my string 0.000"
HaveDigits = False
For i = 1 To Len(sString)
sChr = Mid(sString, i, 1)
If IsNumeric(sChr) Or sChr = "." Then
sStr = sStr & sChr
HaveDigits = True
ElseIf HaveDigits Then
Exit For
End If
Next
MsgBox sStr
End Sub

On Tue, 5 Oct 2004 15:16:43 -0400, "Tom Ogilvy" wrote:

Already did -- but here it is again.

Sub Tester5()
Dim sString As String, sStr As String
Dim i As Long, sChr As String
sString = "This is my string 0.000"
For i = 1 To Len(sString)
sChr = Mid(sString, i, 1)
If IsNumeric(sChr) Or sChr = "." Then
sStr = sStr & sChr
End If
Next
MsgBox sStr

End Sub

gave me 0.000






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing a text string into separate cells Bobalew Excel Worksheet Functions 1 June 6th 07 09:16 PM
String parsing with variable lenght strings frosterrj Excel Worksheet Functions 10 March 31st 06 11:46 PM
Parsing when deliminator is a string Rose Excel Worksheet Functions 5 December 14th 04 12:54 AM
Parsing a string to retrieve numerals nabukhalaf Excel Programming 2 October 5th 04 10:23 PM
Unicode string parsing? Please help! Douglas Gennetten[_2_] Excel Programming 1 January 16th 04 08:31 AM


All times are GMT +1. The time now is 04:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"