Dear Harpreet
I have attach the example showing the proper usage of
access public and private variable.


''''''Module1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Public publicvar1 As Integer
Public publicvar2 As Integer
Public publicvar3 As Integer


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub private_var()
Dim a As Integer
Dim b As Integer
Dim c As Integer
a = Application.InputBox("Enter a 1'st number")
b = Application.InputBox("Enter a 2'nd number")
c = a + b
MsgBox "The addition of 2 variable is:" & c
End Sub
Sub public_var()
publicvar1 = Application.InputBox("Enter a 1'st number")
publicvar2 = Application.InputBox("Enter a 2'nd number")
publicvar3 = publicvar1 * publicvar2
MsgBox "The multiplication of Two variable is:" & publicvar3
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''Module2
Option Explicit
Sub access_md()
Call public_var
MsgBox "First public variable value is:" & publicvar1
MsgBox "First public variable value is:" & publicvar2
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''




I hope it will help.
Happy To Help
:)
Shyam


On Thu, Mar 4, 2010 at 9:47 AM, Harpreet Gujral <[email protected]>wrote:

> Thanks shyam,
>
> Can you tel me wher should I declare a variable in the workbook, which can
> be used in different modules
>
> Harpreet
>
> Sent on my BlackBerry® from Vodafone Essar
> ------------------------------
> *From: * rf1234 rf1234 <[email protected]>
> *Date: *Thu, 4 Mar 2010 00:34:23 +0530
> *To: *<[email protected]>
> *Cc: *<[email protected]>
> *Subject: *Re: $$Excel-Macros$$ Data in variables
>
> Hello Dear
> definately it is possible,when u write the code for particular
> workbook in module,it will reside till workbook exist.
>
>
> hope it will help.
> happy to help
> :)
> shyam
>
> On Mon, Mar 1, 2010 at 2:31 AM, Harpreet Singh Gujral <
> [email protected]> wrote:
>
>> Hi,
>>
>> Is it possible to keep the value stored in the variable till the time the
>> sheet is running or the code is running.
>>
>> Example: I have to a variable A and B, which i need to use to store
>> information from a form, this information will be used in other modules or
>> procedures. Is it possbile to keep the value stored in the variables till
>> the time the sheet is open. Because i may require this information in
>> different small procedures, which run at a different time.
>>
>> Please suggest
>>
>> Harpreet
>>
>>
>> --
>>
>> ----------------------------------------------------------------------------------
>> Some important links for excel users:
>> 1. Follow us on TWITTER for tips tricks and links :
>> http://twitter.com/exceldailytip
>> 2. Join our Facebook Group @
>> http://www.facebook.com/group.php?gid=287779555678
>> 3. Excel tutorials at http://www.excel-macros.blogspot.com
>> 4. Learn VBA Macros at http://www.quickvba.blogspot.com
>> 5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
>>
>> To post to this group, send email to [email protected]
>>
>> <><><><><><><><><><><><><><><><><><><><><><>
>> HELP US GROW !!
>>
>> We reach over 6,800 subscribers worldwide and receive many nice notes
>> about the learning and support from the group.Let friends and co-workers
>> know they can subscribe to group at
>> http://groups.google.com/group/excel-macros/subscribe
>>
>
>

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our Facebook Group @ http://www.facebook.com/group.php?gid=287779555678
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to [email protected]

<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 6,800 subscribers worldwide and receive many nice notes about the 
learning and support from the group.Let friends and co-workers know they can 
subscribe to group at http://groups.google.com/group/excel-macros/subscribe

Reply via email to