Greetings,
A while back I asked how to remove the letters from entries that have both numbers and letters. I as pointed to a UDF called "ExtractNumber".
Here is the code for that UDF:
Code
Function ExtractNumber(rCell As Range)
Dim iCount As Integer, i As Integer
Dim sText As String
Dim lNum As String
''''''''''''''''''''''''''''''''''''''''''
'Written by OzGrid Business Applications
'www.ozgrid.com
'Extracts a number from a cell containing text and numbers.
''''''''''''''''''''''''''''''''''''''''''
sText = rCell
For iCount = Len(sText) To 1 Step -1
If IsNumeric(Mid(sText, iCount, 1)) Then
i = i + 1
lNum = Mid(sText, iCount, 1) & lNum
End If
If i = 1 Then lNum = CInt(Mid(lNum, 1, 1))
Next iCount
ExtractNumber = CLng(lNum)
End Function
Display More
It seemed to work great.
Recently, I noticed that it has a bug that only shows up under one confition, if the number has a decimal in it. In the situation, the result is the number will come out as if there was no decimal (Eg.: "5.75 grams" comes out as "575" instead of "5.75").
Is there any way to fix this bug?
Any help is appreciated.
-Minitman