LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
K K is offline
external usenet poster
 
Posts: 108
Default Alphanumeric udf question.

Guys I found a code to extract numeric, decimal or negative values from a
alphanumeric value. It works great, my problem is that I want to use it for
an array in a sumproduct.

For example,

AL 8
AL 2
NI 3
AL 2

I want to use =SUMPRODUCT(LEFT(A1:A4,2)="AL",(ExtractNumber(A1:A 4,,TRUE)))
but I'm getting a #value error because the extract number UDF doens't allow
me to take an array.

Here is the code for your reference:

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

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)


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


ExtractNumber = CDbl(lNum)

End Function




 
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
Alphanumeric hardeep via OfficeKB.com Excel Worksheet Functions 21 July 29th 08 06:12 PM
ALPHANUMERIC shashidhar Excel Worksheet Functions 5 January 28th 08 02:09 AM
Sort alphanumeric Arran Excel Discussion (Misc queries) 15 November 26th 06 09:41 PM
sort alphanumeric William Excel Discussion (Misc queries) 4 November 13th 06 11:11 PM
a tough question - calculating a number out of an alphanumeric code usingexcel Excel Discussion (Misc queries) 2 August 3rd 06 06:07 PM


All times are GMT +1. The time now is 12:11 AM.

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"