ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Function/Sub (https://www.excelbanter.com/excel-programming/400136-function-sub.html)

LesHurley

Function/Sub
 
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

SeanC UK[_2_]

Function/Sub
 
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.
--
(please remember to click yes if replies you receive are helpful to you)


"LesHurley" wrote:

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


Bob Phillips

Function/Sub
 
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)



"LesHurley" wrote in message
...
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




LesHurley

Function/Sub
 
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.--


"Bob Phillips" wrote:

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)



"LesHurley" wrote in message
...
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





Chip Pearson

Function/Sub
 
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)


"LesHurley" wrote in message
...
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.--


"Bob Phillips" wrote:

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)



"LesHurley" wrote in message
...
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






LesHurley

Function/Sub
 
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.
--
Les

"Chip Pearson" wrote:

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)


"LesHurley" wrote in message
...
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.--


"Bob Phillips" wrote:

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)



"LesHurley" wrote in message
...
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






All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com