Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Don Don is offline
external usenet poster
 
Posts: 487
Default "Using A Variable On Several Sheets"

Hi There,

Hope I can explain this correctly...I have a variable that was assigned a
numerical value using code identifying the last row used on "Sheet1". The
value of the variable changes as data changes on "Sheet1". I need to be able
to pick up this numerical value in code for several other sheets in the same
WB. Is there a method to store this variable so as to be able to use it from
all sheets in the WB?

Probably something very simple but I'm still learning....:)

TIA....Don
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default "Using A Variable On Several Sheets"

Declare the variable as Public at the top of a standard module instead of
inside a procedure. Then when your code modifies it, the other code can also
refer to its value. For example:

Public myRow As Long

Sub Procedure1()
myRow = 100
End Sub

Sub Procedure2()
MsgBox myRow
End Sub

The variable's value will persist as long as the workbook is open or until
an unhadled error occurs.

Greg


"Don" wrote:

Hi There,

Hope I can explain this correctly...I have a variable that was assigned a
numerical value using code identifying the last row used on "Sheet1". The
value of the variable changes as data changes on "Sheet1". I need to be able
to pick up this numerical value in code for several other sheets in the same
WB. Is there a method to store this variable so as to be able to use it from
all sheets in the WB?

Probably something very simple but I'm still learning....:)

TIA....Don

  #3   Report Post  
Posted to microsoft.public.excel.programming
Don Don is offline
external usenet poster
 
Posts: 487
Default "Using A Variable On Several Sheets"

Thanks for the quick reply Greg....really appreciate your help.

Don

"Greg Wilson" wrote:

Declare the variable as Public a

t the top of a standard module instead of
inside a procedure. Then when your code modifies it, the other code can also
refer to its value. For example:

Public myRow As Long

Sub Procedure1()
myRow = 100
End Sub

Sub Procedure2()
MsgBox myRow
End Sub

The variable's value will persist as long as the workbook is open or until
an unhadled error occurs.

Greg


"Don" wrote:

Hi There,

Hope I can explain this correctly...I have a variable that was assigned a
numerical value using code identifying the last row used on "Sheet1". The
value of the variable changes as data changes on "Sheet1". I need to be able
to pick up this numerical value in code for several other sheets in the same
WB. Is there a method to store this variable so as to be able to use it from
all sheets in the WB?

Probably something very simple but I'm still learning....:)

TIA....Don

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default "Using A Variable On Several Sheets"

I should mention that it only needs to be Public if the other code is in
different modules (e.g. worksheet class modules, ThisWorkbook module,
userform modules). If the other code is all in the same standard module, you
can simply declare it at the top of the module thus:

Dim myRow as Long

Greg

"Don" wrote:

Thanks for the quick reply Greg....really appreciate your help.

Don

"Greg Wilson" wrote:

Declare the variable as Public a

t the top of a standard module instead of
inside a procedure. Then when your code modifies it, the other code can also
refer to its value. For example:

Public myRow As Long

Sub Procedure1()
myRow = 100
End Sub

Sub Procedure2()
MsgBox myRow
End Sub

The variable's value will persist as long as the workbook is open or until
an unhadled error occurs.

Greg


"Don" wrote:

Hi There,

Hope I can explain this correctly...I have a variable that was assigned a
numerical value using code identifying the last row used on "Sheet1". The
value of the variable changes as data changes on "Sheet1". I need to be able
to pick up this numerical value in code for several other sheets in the same
WB. Is there a method to store this variable so as to be able to use it from
all sheets in the WB?

Probably something very simple but I'm still learning....:)

TIA....Don

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
"Count" and "List" functions across sheets Meg Excel Worksheet Functions 0 October 14th 08 02:11 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"Type mismatch" when I try to fill an Array variable with "+" [email protected] Excel Discussion (Misc queries) 1 April 17th 07 01:28 PM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" Luc[_3_] Excel Programming 2 September 28th 05 08:37 PM
Naming convention for a variable "Book1" while copying sheets JER Excel Programming 6 April 3rd 04 08:54 PM


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