PDA

View Full Version : [SOLVED] Can you call a Sub from a Function?



thepr1nter
09-26-2005, 11:00 AM
Title says it all. Can you? :dunno

A function cannot modify a worksheet but a subroutine can. So can you call a subroutine from a function to modify a range of cells?

MWE
09-26-2005, 11:10 AM
Title says it all. Can you? :dunno

A function cannot modify a worksheet but a subroutine can. So can you call a subroutine from a function to modify a range of cells?
Assuming you are refering to VBA functions and subs: not sure where you told that a function cannot modify a worksheet. They can and I have some that do. It is probably not a good practice to do that, but ...

Functions can call subs or anything else. I have numerous functions that call subs which call other functions, etc. There may be a practical limit to "things calling things", but I have never encountered it.

Jacob Hilderbrand
09-26-2005, 11:10 AM
You can Call a Sub, but you still cannot modify the worksheet if the Function is called from a cell. If the Function is called from a Sub then you have more options.

Bob Phillips
09-26-2005, 11:12 AM
Title says it all. Can you? :dunno

A function cannot modify a worksheet but a subroutine can. So can you call a subroutine from a function to modify a range of cells?

Of course you can, but if you try and modify the worksheet in a sub called from a function invoked within the worksheet it will fail.

You don't get around it that easily <vbg>.

.

mvidas
09-26-2005, 11:12 AM
Hi thepr1nter, thanks for stopping back :)

While you can call a sub from a function, you still can't manipulate a worksheet from a worksheet function calling a sub even if that sub has the actual code.

Sorry
Matt