Re: Extract Digits Questions



It changes it to numeric.

This is what you want

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
ExtractDigits = ExtractDigits * 1
Exit Function
End If
End If
Next i
End Function



--

HTH

RP
(remove nothere from the email address if mailing direct)


<rrstudio2@xxxxxxxxxxx> wrote in message
news:1135712385.873461.103040@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I found a nice function and modified it to take out digits (and a
> decimal) from a cell however don't get one line. 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
> Else
> If flag = 1 Then Exit Function
> End If
> Next i
> End Function
> ---------------------------------
> This seems to work, however if the cell is 12.3mg it will display the
> result as 123. If I comment out the ExtractDigits = ExtractDigits * 1
> then it returns it as 12.3 which is what I want. So what is this
> ExtractDigits = ExtractDigits * 1 doing? I can't figure out why it
> changes 123 to 12.3.
>
> Thanks,
> Andrew V. Romero
>


.



Relevant Pages

  • Extract Digits Questions
    ... 'extract 1st continuous set of digits ... Dim i As Long, flag As Long ... however if the cell is 12.3mg it will display the ...
    (microsoft.public.excel.programming)
  • Re: Extract 5 digit number from string
    ... I only want the part to be extract which have 5 digits after each ... The following VBA UDF gives the desired result in all of your examples. ... Function Extr5D(str As String) As String ...
    (microsoft.public.excel.programming)
  • Re: Regular expression 0 - number range.
    ... It might be easier to extract the digits, parseInt and check that the ... especially if you're parsing user input. ...
    (comp.lang.javascript)
  • Extract Digit Function Question
    ... I found a function which seperates out numbers from letters. ... 'extract 1st continuous set of digits ... Dim i As Long, flag As Long ...
    (microsoft.public.excel.programming)
  • RE: Validate User Input in Dialog box
    ... Dim Flag As Boolean ... Dim StartingNum As Long ... "Enter Starting Number (5 digits only)") ...
    (microsoft.public.excel.programming)