#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default Global Variable

How can I define a global variable that is accessible to any subroutine in
any module of the workbook? Thanks for any help on this.


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Global Variable

Above and outside of any procedure in the module, declare the variable
with a declaration like:

Public MyVar As Long

This variable will be accessible from any procedure in any module of
the VBA project (and to other VBA projects that reference this one)
and will retain its value after a procedure terminates.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 26 Jul 2009 05:56:01 -0700, dhstein
wrote:

How can I define a global variable that is accessible to any subroutine in
any module of the workbook? Thanks for any help on this.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default Global Variable

Thanks Chip.

David


"Chip Pearson" wrote:

Above and outside of any procedure in the module, declare the variable
with a declaration like:

Public MyVar As Long

This variable will be accessible from any procedure in any module of
the VBA project (and to other VBA projects that reference this one)
and will retain its value after a procedure terminates.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 26 Jul 2009 05:56:01 -0700, dhstein
wrote:

How can I define a global variable that is accessible to any subroutine in
any module of the workbook? Thanks for any help on this.


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,934
Default Global Variable

To make the variable global to the entire workbook, declare it as Public in
the variable as Public in the (General)(Declarations) section of any normal
(BAS) Module. If you don't have any modules in your project, click
Insert/Module on the VB editor's Menu Bar and use that one. Here is an
example of what a declaration would look like (in this case, for a String
variable, but any valid data type may be specified)...

Public MyGlobalVariable As String

--
Rick (MVP - Excel)


"dhstein" wrote in message
...
How can I define a global variable that is accessible to any subroutine in
any module of the workbook? Thanks for any help on this.



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,420
Default Global Variable

You can also call it Global, works the same as Public, maybe more
informative.

--
__________________________________
HTH

Bob

"Rick Rothstein" wrote in message
...
To make the variable global to the entire workbook, declare it as Public
in the variable as Public in the (General)(Declarations) section of any
normal (BAS) Module. If you don't have any modules in your project, click
Insert/Module on the VB editor's Menu Bar and use that one. Here is an
example of what a declaration would look like (in this case, for a String
variable, but any valid data type may be specified)...

Public MyGlobalVariable As String

--
Rick (MVP - Excel)


"dhstein" wrote in message
...
How can I define a global variable that is accessible to any subroutine
in
any module of the workbook? Thanks for any help on this.





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
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
I Need VBA Assistance for global variable question Brent E Excel Discussion (Misc queries) 1 March 1st 05 08:46 PM
Global Variable -- Excel / VBA Adam1 Chicago Excel Discussion (Misc queries) 3 February 23rd 05 12:03 AM


All times are GMT +1. The time now is 09:29 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"