Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Defining a variable within a sub...


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Defining a variable within a sub...

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
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
Defining a variable length area for output. JHB Excel Discussion (Misc queries) 2 August 5th 09 10:43 PM
Defining UserForm Caption from a Variable [email protected] Excel Worksheet Functions 1 January 3rd 07 02:30 PM
Defining a variable within a sub... aking1987[_2_] Excel Programming 1 November 11th 04 12:32 PM
Defining a variable within a sub... aking1987 Excel Programming 1 November 11th 04 11:00 AM
Defining a Variable Stephen[_3_] Excel Programming 1 September 8th 03 11:33 PM


All times are GMT +1. The time now is 01:05 PM.

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

About Us

"It's about Microsoft Excel"