Passed Arguments to a UDF
On Sat, 22 Nov 2008 14:38:56 -0500, "Bob Myers" wrote:
Ron, this is going to get messy -- but you asked, and thanks.
My previous rendition was simplified. The following accurately reflects the
actual.
F14 holds:
'=IF(OR(nBank=0,A14="S"),"",COUNTIF(G14:OFFSET(F1 4,0,iWk3),"=x"))'
Where nBank is set on another tab and is 12, and iWk3 is set on this tab and
is 18.
It returns the number of x's in the first 18 Cells of Range G14:AO14,
which is 2.
G14:AO14 holds:
'|*|22|20|x|22|20|*|19|20|*|18|17|x|19|20|*|23|24 |*|25|21|*|20|21|x|18|17|*|*|*|*|*|*|'
Where * = Null (empty, blank)
AQ14 holds: '=FBank(F14, G14:AO14)'
UDF header: 'Function FBank(ub As Integer, rRange As Range)'
With F14 in the function call, ub is always 0, which includes 'ByVal ub As
Integer.'
I've also tried 'ub As Variant,' and still ub = 0.
If I set D14 to '=F14' and change FBank's call to FBank(D14, G14:AO14), ub =
0;
but if I set D14 to 2, ub will be 2.
If I change FBank's call to FBank(F14:AO14) and read the first cell, it will
be 0.
If I change FBank's call to FBank(ROW(), G14:AO14), the row comes thru as
14;
but 'ub = Range("F14")' still comes out as 0; as does
Range("Sheet!F14").
If I change the FBank call to FBank(2, G14:AO14), ub will be 2.
I've tried as many work-arounds as I can think of to get the value of F14
into my UDF.
Although it would be nice to know why I can't, I'd be be semi-happy just to
get it there.
Using your information to reproduce what you have done, I have no problem with
the values you have used.
Again, how are you determining that ub is not being properly passed?
Since you did not indicate that, I used a very simple UDF:
Function FBank(ub As Integer, rRange As Range)
FBank = ub
End Function
As expected, the function returned a value of 2.
--ron
|