Function/Sub

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to make a VBA Function call a Sub ? I don't have any problem
calling either from one of the same kind.--
Thanks for your help
 
Hi Les,

You can certainly call Subs from Functions, and vice versa. However, if you
create a function to be used in a worksheet, then I don't believe you can
call a Sub that performs any actions to worksheets. Calling a function from a
worksheet only allows you to return a result to the cell calling the function.

I believe this to be the case/

Sean.
 
In VBA yes. A function can call a sub and vice versa.

What makes you think that it might not?

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
well maybe Sean answered it. Suppose I have:

Sub Good()
Selection.Value="Good"
End Sub

Function OK()
Good
End Function

The Sub procedure works OK, it returns "Good" to the selected cell in the
worksheet by clicking tools/macros/good, but typing =OK() gives a #NAME
error.--
 
A Function or Sub called from a worksheet cell, directly or indirectly,
cannot modify any part of the Excel environment, including changing the
contents of any cell, including the cell from which it was called. I'm
surprised that you get a #NAME error. I would have expected that you would
get a #VALUE error.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
OK; I was beginning to realize that: I had some cockpit error when I
reported a #NAME? error. What I really got was a circular reference error
which I guess makes sense. Subs can change stuff on the worksheet sao I
thought maybe I could do multiple stuff with a function by calling a Sub from
the function. Thanks.
 

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

Back
Top