Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I would like define the variable with different balues either way of the if then statement. BUT, use these varialbes within another sub. IE: define the variable within one sub, but use it in another. -- aking1987 ------------------------------------------------------------------------ aking1987's Profile: http://www.excelforum.com/member.php...o&userid=15393 View this thread: http://www.excelforum.com/showthread...hreadid=277313 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Either define them at module level or pass them
as arguments to the procedure. in short: Dim x As Long Sub proA() Dim y As Long x = 10 y = 1 Call proB Debug.Print x; y Call proC(y) Debug.Print x; y Call proD(y) Debug.Print x; y End Sub Sub proB() x = 20 End Sub Sub proC(z As Long) 'in vba arguments are passed byref unless specified otherwise) z = z * 2 'y in the calling proc has now changed x = x * z End Sub Sub proD(ByVal z As Integer) z = -1 'y is NOT changed, as z is Byval 'note you can also mix datatypes 'to a certain extent... x = x * z End Sub in great detail described here. http://msdn.microsoft.com/library/de...l=/library/en- us/modcore/html/decontipsfordefiningproceduresinvba.asp understanding arguments and variables is VERY important. please buy a good VBA book. -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam aking1987 wrote in message : I would like define the variable with different balues either way of the if then statement. BUT, use these varialbes within another sub. IE: define the variable within one sub, but use it in another. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Defining a variable length area for output. | Excel Discussion (Misc queries) | |||
Defining UserForm Caption from a Variable | Excel Worksheet Functions | |||
Defining a variable within a sub... | Excel Programming | |||
Defining a variable within a sub... | Excel Programming | |||
Defining a Variable | Excel Programming |