Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Possible to call a procedure inside a function?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Possible to call a procedure inside a function?

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.


In article . com,
"suomi" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Possible to call a procedure inside a function?

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):
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.


In article . com,
"suomi" wrote:

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


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
how to call a function procedure nathan Excel Programming 4 January 17th 06 06:56 PM
Where else to look for procedure call Lulu Excel Programming 0 November 24th 04 03:07 PM
Call a proc inside itself (HELP) David Excel Programming 2 February 4th 04 08:28 PM
call procedure bob Excel Programming 1 August 9th 03 12:40 AM
procedure won't call John Gittins Excel Programming 0 August 5th 03 08:17 PM


All times are GMT +1. The time now is 07:38 AM.

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"