P. 1
Extract Number From Text (Excel)

Extract Number From Text (Excel)

|Views: 1|Likes:
Published by jitinmangla970

More info:

Published by: jitinmangla970 on May 07, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less





Function ExtractNumber(rCell As Range, _ Optional Take_decimal As Boolean, Optional Take_negative As Boolean) As Dou ble

Dim iCount As Integer, i As Integer, iLoop As Integer Dim sText As String, strNeg As String, strDec As String Dim lNum As String Dim vVal, vVal2

'''''''''''''''''''''''''''''''''''''''''' 'Written by OzGrid Business Applications 'www.ozgrid.com

'Extracts a number from a cell containing text and numbers. '''''''''''''''''''''''''''''''''''''''''' sText = rCell If Take_decimal = True And Take_negative = True Then strNeg = "-" 'Negative Sign MUST be before 1st number. strDec = "." ElseIf Take_decimal = True And Take_negative = False Then strNeg = vbNullString strDec = "." ElseIf Take_decimal = False And Take_negative = True Then strNeg = "-" strDec = vbNullString End If iLoop = Len(sText)

For iCount = iLoop To 1 Step -1 vVal = Mid(sText, iCount, 1)

1)) Next iCount ExtractNumber = CDbl(lNum) End Function . 1. iCount. .If IsNumeric(vVal) Or vVal = strNeg Or vVal = strDec Then i = i + 1 lNum = Mid(sText. 1) & lNum If IsNumeric(lNum) Then If CDbl(lNum) < 0 Then Exit For Else lNum = Replace(lNum. 1). 1) End If End If If i = 1 And lNum <> vbNullString Then lNum = CDbl(Mid(lNum. "". Left(lNum.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->