Passed Arguments to a UDF
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(F14 ,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.
R/Bob
"Ron Rosenfeld" wrote in message
...
On Fri, 21 Nov 2008 23:42:45 -0500, "Bob Myers" wrote:
I have a problem passing arguments to a UDF. I believe it is a specific
problem since I've passed a lot of arguments to a lot of other UDF's in
the
past. I'm working with Excel 2003 on Vista.
The Workbook looks like:
[F14] [G14 <Range
R14] [S14]
F14 has a formula that produces an Integer as a function of what's in the
Range.
G14:R14 is mostly integers, but with a few alphas and nulls.
S14 has a formula containing the UDF Action(F14, G14:R14).
The UDF takes the form:
Function Action(X As Integer, Rrrr As Range) As Integer
...
Stuff
...
End Function
My problem is the only value I can get out of X is 0 (zero), regardless of
what's in F14.
I've tried ByVal X and the default, ByRef X. Still 0.
I've tried putting an Integer in B3 and passing B3 instead of F14. Still
0.
Since I'm able to pick every cell out of Range Rrrr in the UDF, I've tried
extending Rrrr to F14:R14 (changed
the passed arguments accordingly). Regardless of what's in the first
cell of the Rrrr, all I can still get is a 0.
If I change the Call to Action(3, G14:R14), the 3 comes through for the
value of X.
Any ideas, suggestions?
Respectfully submitted,
Bob Myers
Need more information.
What is the formula in F14, and the precedents to that formula?
How are you determining that the "value you get out of X) is zero?
The only way I have been able to get the following to return a zero is if
X<1.
Even if X is a text string, (i.e. "1") I still return a one.
======================
Function Action(X As Integer, Rrrr As Range) As Integer
MsgBox (X)
End Function
==================
--ron
|