Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / August 2007

Tip: Looking for answers? Try searching our database.

Create a variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gatarossi@ig.com.br - 29 Aug 2007 11:56 GMT
Dear all,

In my VBA project I have a lot of codes...

But I want that in one code create a variable to use in another code.

For example:

sub code_1()

dim x as variant

set x = 10

end sub

sub code_2()

for i = x
.
.
.
end sub

How can I do this? And what I need to do for update de variable?

Thanks a lot!!!

André.
Dave Peterson - 29 Aug 2007 12:26 GMT
One way:

Option Explicit
Dim x as long  'this variable is visible to just this module
Public y as long 'this variable is visible to all modules

sub code_1()
 x = 10  'no set required
end sub

sub code_2()
 dim i as long
 for i = x
   ...
 next i
end sub

Another way is to pass the value between subroutines:

Option Explicit
sub code_1()
 x = 10  'no set required
 call code_2A(SomeVar:=x)
end sub

sub code_2a(SomeVar as long)
 dim i as long
 for i = SomeVar
   ...
 next i
end sub

> Dear all,
>
[quoted text clipped - 25 lines]
>
> André.

Signature

Dave Peterson


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.