LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Problem with VBA Functions that use a DefinedRange as parameter

If I set up a simple spreadsheet with Column A being a defined range named
TestRange. I can then in column B use the formula =TestRange for each cell
and get the value that is in A.

But if I create a function
Public Function fxVal(ByVal a As Variant)
fxVal = a
End Function
and copy it down column C I get the value of the first item in the range only

A B C
TestRange =TestRange =fxVal(TestRange)
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1


Further if I make a column D that is =2*TestRange I get the expected values,
but if I use a function
Public Function fxTimesTwo(ByVal a As Variant)
fxTimesTwo = 2 * a
End Function

I get #Value! for each cell...

D E
=2*TestRange =fxTimesTwo(TestRange)
2 #VALUE!
4 #VALUE!
6 #VALUE!
8 #VALUE!
10 #VALUE!

In dealing with this issue, I have determined that the DefinedRange is
passed to the function as a VarType=8204 vbArray+vbVariant. I have tried
using CInt to the passed variable and countless other things but cannot
resolve from within the Function.

I can obviously resolve the issue from within the spreadsheet by calling the
function with cell addresses ie fxVal(A3).
Also, I can use fxVal(Int(TestRange)) and the functions will work. From
researching this it appears that the Int(TestRange) will convert the
parameter to an individual element double...

Obviously, since Excel has countless internal functions, ie SQRT(TestRange)
that work fine, there should be someway that my man made function should be
able to handle the named range from within the function.

Any help appreciated...

 
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
Problem setting each parameter in an Array = Nothing RyanH Excel Programming 8 July 26th 08 10:15 AM
Does the COUNTIF criteria parameter accepts functions? [email protected] Excel Worksheet Functions 3 May 22nd 08 09:50 AM
parameter problem Gixxer_J_97[_2_] Excel Programming 3 June 3rd 05 05:32 PM
User defined functions - parameter descriptions Heidi[_4_] Excel Programming 7 July 20th 04 08:03 PM
Problem with ADO with Parameter Object Tod Excel Programming 1 May 7th 04 11:03 AM


All times are GMT +1. The time now is 09:30 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"