Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default 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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default 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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Excel - User Defined Function Error: This function takes no argume BruceInCalgary Excel Programming 3 August 23rd 06 08:53 PM
Need to open the Function Arguments window from VBA for a user defined function. [email protected] Excel Programming 0 June 20th 06 03:53 PM


All times are GMT +1. The time now is 10:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"