Possible to call a procedure inside a function?

S

suomi

Hello group,
How can I call a procedure in a function? Is this allowed or do I have
to change the function into a procedure? To simplify, problem looks
like this:

Sub WriteHere(What As Integer)
ActiveCell.Offset(1, 0).Value = What
End Sub

Function Count(What As Integer)
Call WriteHere(What)
Count = What ^ 2
End Function

The argument from function is not passed to the procedure. The function
is not calculated.
Can you advise on this? Cheers
 
J

JE McGimpsey

You can call the procedure from the function, but the procedure can't
assign values to a worksheet. Functions, and procedures called from
functions, can only return values to their calling cells.

When I run your code (after renaming Count() to something that isn't a
built-in function name), the argument is passed to the procedure, but
the procedure can't affect the other cell.
 
S

suomi

Hi,
Thanks for your explanation. I did not know, that called sub cannot
affect any other cell's value but it seems to be true; because when I
changed code in the sub to e.g. set interior colour, depending on the
argument, the function worked.
However, it does not solve my problem. What I had in my mind was to
create a function that would return one value and in the same time
would fill a table with summary information. I guess it must be done
with two procedures then.
Cheers,


JE McGimpsey napisal(a):
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top