|
-
March 1st, 2012, 06:01 PM
#1
Is there a better VAL()?
As you know, Val() stops at commas, parentheses, etc, but ignores spaces between separate numbers!
CDBL(strTxt) offers help, but only if the string is fully numeric
I often write code to process copied text, and want to extract The number in a line like this
Profit/Loss: ($12,000.95) -- thru July
Is there a function for this, or do I have to write one myself?
Appreciate any help
-
March 2nd, 2012, 08:03 AM
#2
Re: Is there a better VAL()?
I think you'd have to make use of the string functions to locate and extract numeric values from text.
If you are sure to have the $ leading a number you can locate it with InStr().
If the $ is not to be expected always, you'd have to walk through the string character by character until the first numeric digit.
Then you walk throiugh the following characters until the next non-numeric (accepting "," and ".").
Then you'd use Mid$ to extract the substring and then, if you want to use the CDbl() or Val(), you'd have to use Replace() to remove the comma.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|