You are on page 1of 1

Function ExtrageNumar(rCell As Range, _

Optional CuZecimale As Boolean, Optional Negative As Boolean) As Double


Dim
Dim
Dim
Dim

iCount As Integer, i As Integer, iLoop As Integer


sText As String, strNeg As String, strDec As String
lNum As String
vVal, vVal2
sText = rCell
If CuZecimale = True And Negative = True Then
strNeg = "-"
strDec = "."
ElseIf CuZecimale = True And Negative = False Then
strNeg = vbNullString
strDec = "."
ElseIf CuZecimale = False And Negative = True Then
strNeg = "-"
strDec = vbNullString
End If
iLoop = Len(sText)
For iCount = iLoop To 1 Step -1
vVal = Mid(sText, iCount, 1)
If IsNumeric(vVal) Or vVal = strNeg Or vVal = strDec Then
i = i + 1
lNum = Mid(sText, iCount, 1) & lNum
If IsNumeric(lNum) Then
If CDbl(lNum) < 0 Then Exit For
Else
lNum = Replace(lNum, Left(lNum, 1), "", , 1)
End If
End If
If i = 1 And lNum <> vbNullString Then lNum = CDbl(Mid(lNum, 1,

1))
Next iCount
ExtrageNumar = CDbl(lNum)
End Function

You might also like