Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Extract Digit Function Question

I found a function which seperates out numbers from letters. I
modified the formula to keep decimal points in. The formula works
well, however, the function came with a line that I don't understand.
The whole function is
------------------------------
Function ExtractDigits(cell As String) As Variant
'extract 1st continuous set of digits
'David McRitchie, 2001-09-26
Dim i As Long, flag As Long
flag = 0
ExtractDigits = ""
For i = 1 To Len(cell)
If Mid(cell, i, 1) = "0" And _
Mid(cell, i, 1) <= "9" Or _
Mid(cell, i, 1) = "." Then
flag = 1
ExtractDigits = ExtractDigits & Mid(cell, i, 1)
'ExtractDigits = ExtractDigits * 1 'not sure what this does?
but 12.3=123 with on
Else
If flag = 1 Then Exit Function
End If
Next i
End Function
-----------------------------
I don't see what the purpose of the ExtractDigits = ExtractDigits * 1
is and I don't get what it is doing. If it is enabled, like it was in
the original formula, then if the cell is 12.3mg it returns 123 while
if it is disabled, then it returns 12.3. How is this line removing the
decimal point?

Thanks,
Andrew V. Romero

PS: Sorry if this message comes thru multiple times, Google groups
seems to be acting up.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Extract Digit Function Question

Ignore, see the slightly older thread. There was apparently over an
hour delay in posting messages this morning....
-Andrew

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Extract Digit Function Question

Testing your function with the *1 in it does this

? ExtractDigits("abcd12.3efgh")
12.3

so the problem is (besides your post with 4 responses which you ignored and
wasted people's time - however, that is an indicator) that you screwed up
and formatted your cell not to show decimal places.

It works without the *1 because then the function returns a text string and
as many know, a text string is not formatted by a number format.

When you apply the *1, it converts the result to a number which is affected
by the formatting of the cell. Format your cell to general and a light bulb
should come on.

In any event, Ron Rosenfeld suggested a much simpler function which should
work for the situation you describe (but it would also be affected by cell
formatting).

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
I found a function which seperates out numbers from letters. I
modified the formula to keep decimal points in. The formula works
well, however, the function came with a line that I don't understand.
The whole function is
------------------------------
Function ExtractDigits(cell As String) As Variant
'extract 1st continuous set of digits
'David McRitchie, 2001-09-26
Dim i As Long, flag As Long
flag = 0
ExtractDigits = ""
For i = 1 To Len(cell)
If Mid(cell, i, 1) = "0" And _
Mid(cell, i, 1) <= "9" Or _
Mid(cell, i, 1) = "." Then
flag = 1
ExtractDigits = ExtractDigits & Mid(cell, i, 1)
'ExtractDigits = ExtractDigits * 1 'not sure what this does?
but 12.3=123 with on
Else
If flag = 1 Then Exit Function
End If
Next i
End Function
-----------------------------
I don't see what the purpose of the ExtractDigits = ExtractDigits * 1
is and I don't get what it is doing. If it is enabled, like it was in
the original formula, then if the cell is 12.3mg it returns 123 while
if it is disabled, then it returns 12.3. How is this line removing the
decimal point?

Thanks,
Andrew V. Romero

PS: Sorry if this message comes thru multiple times, Google groups
seems to be acting up.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Extract Digit Function Question

for completeness, I had changed the location of the *1 - but the formatting
is another possibility.

Function ExtractDigits(cell As String) As Variant
'extract 1st continuous set of digits
'David McRitchie, 2001-09-26
Dim i As Long, flag As Long
flag = 0
ExtractDigits = ""
For i = 1 To Len(cell)
If Mid(cell, i, 1) = "0" And _
Mid(cell, i, 1) <= "9" Or _
Mid(cell, i, 1) = "." Then
flag = 1
ExtractDigits = ExtractDigits & Mid(cell, i, 1)
Else
If flag = 1 Then Exit Function
End If
Next i
ExtractDigits = ExtractDigits * 1
End Function

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
Testing your function with the *1 in it does this

? ExtractDigits("abcd12.3efgh")
12.3

so the problem is (besides your post with 4 responses which you ignored

and
wasted people's time - however, that is an indicator) that you screwed up
and formatted your cell not to show decimal places.

It works without the *1 because then the function returns a text string

and
as many know, a text string is not formatted by a number format.

When you apply the *1, it converts the result to a number which is

affected
by the formatting of the cell. Format your cell to general and a light

bulb
should come on.

In any event, Ron Rosenfeld suggested a much simpler function which should
work for the situation you describe (but it would also be affected by cell
formatting).

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
I found a function which seperates out numbers from letters. I
modified the formula to keep decimal points in. The formula works
well, however, the function came with a line that I don't understand.
The whole function is
------------------------------
Function ExtractDigits(cell As String) As Variant
'extract 1st continuous set of digits
'David McRitchie, 2001-09-26
Dim i As Long, flag As Long
flag = 0
ExtractDigits = ""
For i = 1 To Len(cell)
If Mid(cell, i, 1) = "0" And _
Mid(cell, i, 1) <= "9" Or _
Mid(cell, i, 1) = "." Then
flag = 1
ExtractDigits = ExtractDigits & Mid(cell, i, 1)
'ExtractDigits = ExtractDigits * 1 'not sure what this does?
but 12.3=123 with on
Else
If flag = 1 Then Exit Function
End If
Next i
End Function
-----------------------------
I don't see what the purpose of the ExtractDigits = ExtractDigits * 1
is and I don't get what it is doing. If it is enabled, like it was in
the original formula, then if the cell is 12.3mg it returns 123 while
if it is disabled, then it returns 12.3. How is this line removing the
decimal point?

Thanks,
Andrew V. Romero

PS: Sorry if this message comes thru multiple times, Google groups
seems to be acting up.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Extract Digit Function Question

Thanks for the information. It is (as Bob Phillips mentioned in my
other post- again sorry for the multple posting, no messages were being
posted for about 2 hrs) that each digit was being multiplied by 1 so
the 12. * 1 = 12, then the next digit came along 123*1=123. I am
pretty familier with typical excel things, such as formatting, but am
just starting to get a grasp of the power of VB in excel. Looking
foward to learning more about it. Hopefully soon I will be able to be
creating my own instead of modifying other's functions.

-Andrew V. Romero



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
How to extract each digit from a number in one cell? greyhound girl Excel Discussion (Misc queries) 4 November 9th 06 07:42 PM
extract decimal place digit craig_100 Excel Worksheet Functions 3 November 29th 05 06:59 PM
Extract 10 digit number from string R. Choate Excel Programming 20 October 27th 05 10:47 PM
Extract 2, 3, 4 or 5-digit number from string Jim[_55_] Excel Programming 1 June 7th 05 03:22 PM
Extract 2, 3, 4 or 5-digit number from string Jim[_55_] Excel Programming 2 June 6th 05 06:48 PM


All times are GMT +1. The time now is 12:22 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"