Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Input range to UDF ?

My function is

Function nEven(mRange As Range) As Long
Dim cell As Range, score As Integer
For Each cell In mRange
score = cell.Value
If score 10 Then
nEven = nEven + 1
End If
Next cell
End Function

In the worksheet the cells A1 down to C4 have
12 0 0
0 13 0
0 0 45
0 3 0

now then =nEven(A1:C4) works, but =nEven(A1,B2,C3) with three separate cells
does not.

Looking at the second equation, I see that Excel would have trouble telling
the difference a single range with three cells and three separate arguments.

Thanks for any help you can give me.
--
jake
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Input range to UDF ?

in the VBA help for function, look at the information for a paramarray.


ParamArray Optional. Used only as the last argument in arglist to indicate
that the final argument is an Optional array of Variant elements. The
ParamArray keyword allows you to provide an arbitrary number of arguments. It
may not be used with ByVal, ByRef, or Optional.

--
Regards,
Tom Ogilvy


"Jakobshavn Isbrae" wrote:

My function is

Function nEven(mRange As Range) As Long
Dim cell As Range, score As Integer
For Each cell In mRange
score = cell.Value
If score 10 Then
nEven = nEven + 1
End If
Next cell
End Function

In the worksheet the cells A1 down to C4 have
12 0 0
0 13 0
0 0 45
0 3 0

now then =nEven(A1:C4) works, but =nEven(A1,B2,C3) with three separate cells
does not.

Looking at the second equation, I see that Excel would have trouble telling
the difference a single range with three cells and three separate arguments.

Thanks for any help you can give me.
--
jake

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Input range to UDF ?

Function nEven(ParamArray mRange()) As Long
Dim cell As Range, score As Integer
Dim i As Long
For i = LBound(mRange) To UBound(mRange)
If TypeOf mRange(i) Is Range Then
For Each cell In mRange(i)
If cell.Value 10 Then nEven = nEven + 1
Next cell
End If
Next i
End Function



--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Jakobshavn Isbrae" wrote in
message ...
My function is

Function nEven(mRange As Range) As Long
Dim cell As Range, score As Integer
For Each cell In mRange
score = cell.Value
If score 10 Then
nEven = nEven + 1
End If
Next cell
End Function

In the worksheet the cells A1 down to C4 have
12 0 0
0 13 0
0 0 45
0 3 0

now then =nEven(A1:C4) works, but =nEven(A1,B2,C3) with three separate

cells
does not.

Looking at the second equation, I see that Excel would have trouble

telling
the difference a single range with three cells and three separate

arguments.

Thanks for any help you can give me.
--
jake



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Input range to UDF ?

Thank you Bob & Tom. I can't believe how fast you guys are.
--
jake


"Bob Phillips" wrote:

Function nEven(ParamArray mRange()) As Long
Dim cell As Range, score As Integer
Dim i As Long
For i = LBound(mRange) To UBound(mRange)
If TypeOf mRange(i) Is Range Then
For Each cell In mRange(i)
If cell.Value 10 Then nEven = nEven + 1
Next cell
End If
Next i
End Function



--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"Jakobshavn Isbrae" wrote in
message ...
My function is

Function nEven(mRange As Range) As Long
Dim cell As Range, score As Integer
For Each cell In mRange
score = cell.Value
If score 10 Then
nEven = nEven + 1
End If
Next cell
End Function

In the worksheet the cells A1 down to C4 have
12 0 0
0 13 0
0 0 45
0 3 0

now then =nEven(A1:C4) works, but =nEven(A1,B2,C3) with three separate

cells
does not.

Looking at the second equation, I see that Excel would have trouble

telling
the difference a single range with three cells and three separate

arguments.

Thanks for any help you can give me.
--
jake




Reply
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
List Box - For Input Range can I use named range in another workbo dim Excel Worksheet Functions 2 January 3rd 08 06:10 PM
Input range Irishrose28 Charts and Charting in Excel 1 August 4th 06 04:35 PM
Input box range - output range al007 Excel Programming 5 November 21st 05 03:05 PM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Excel Programming 4 December 8th 03 03:22 PM
Macro to input formula in range based on another range Peter Atherton Excel Programming 0 October 9th 03 12:47 AM


All times are GMT +1. The time now is 03:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"