Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Sub-procedures w/in a function

Is it possible to use a subprocedure within a function?
How would you refer to the subprocedure?

I'm trying to create a variable in a subprocedure that is
updated w/ a function, so that the vairable holds the
value and can be used the next time the function is called
upon.

Any help would be greatly appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Using Sub-procedures w/in a function

Either define the variable at a global level, e.g.
Option Explicit
Dim myVar1 as Integer 'can be used by any Sub or
Function on this sheet, retains its value between uses
Public myVar2 as Integer 'can be used by any Sub or
Function in this project, retains its value between uses

:
:

else define the varibale as static within the function,
e.g.

Function TestIt() As Integer
Static myVar3 As Integer
myVar3 = InputBox("Enter a number", "Test it", myVar3)
TestIt = myVar3
End Function

then type
?Testit
in the Immediate pane a couple of times (Ctrl-G if it's
not open)

Kevin Beckham


-----Original Message-----
Is it possible to use a subprocedure within a function?
How would you refer to the subprocedure?

I'm trying to create a variable in a subprocedure that is
updated w/ a function, so that the vairable holds the
value and can be used the next time the function is

called
upon.

Any help would be greatly appreciated!
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Using Sub-procedures w/in a function

Another approach to remember values is to declare a Static value in a sub:

Sub test()
Static L As Long
If L = 0 Then L = 1
L = Doubled(L)
MsgBox "L is now " & L
End Sub

Function Doubled(X As Long) As Long
Doubled = X + X
End Function

I'm not too sure what your question really is. If you want to pass
variables, it's done like above. If you want to run a Sub from a function in
a cell, no that is not possible.
--
HTH. Best wishes Harald
Followup to newsgroup only please

"LizUrish" skrev i melding
...
Is it possible to use a subprocedure within a function?
How would you refer to the subprocedure?

I'm trying to create a variable in a subprocedure that is
updated w/ a function, so that the vairable holds the
value and can be used the next time the function is called
upon.

Any help would be greatly appreciated!



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
Separating sub procedures JAW Excel Discussion (Misc queries) 4 January 28th 09 12:17 PM
VBA function Procedures.... Arif[_2_] Excel Worksheet Functions 1 June 3rd 08 01:54 PM
VBA functions and Procedures.... Arif[_2_] Excel Worksheet Functions 1 June 3rd 08 10:27 AM
what's wrong with this sub procedures? active_x[_4_] Excel Programming 8 September 10th 03 05:25 AM
VBA -- procedures as arguments? Dave Ring Excel Programming 1 August 27th 03 02:27 AM


All times are GMT +1. The time now is 02:07 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"