PC Review


Reply
Thread Tools Rate Thread

Create a variable

 
 
gatarossi@ig.com.br
Guest
Posts: n/a
 
      29th Aug 2007
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é.

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      29th Aug 2007
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



(E-Mail Removed) wrote:
>
> 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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a Random Variable dperez6811@yahoo.com Microsoft Excel Misc 3 25th Aug 2009 09:18 AM
Re: create new variable Pete_UK Microsoft Excel Worksheet Functions 0 23rd Jan 2007 05:41 PM
Create a mirror from 1st subform variable into 2nd subform variable. Eric Microsoft Access 0 14th Aug 2006 05:58 PM
Use a variable anywhere in the workbook - How to create? =?Utf-8?B?Q1JheUY=?= Microsoft Excel Programming 3 29th Sep 2005 10:57 AM
How can i create this variable? Miguel Dias Moura Microsoft VB .NET 2 12th Dec 2004 07:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 AM.