ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Declaring variables for use in multiple worksheets (https://www.excelbanter.com/excel-discussion-misc-queries/260992-re-declaring-variables-use-multiple-worksheets.html)

TomPl

Declaring variables for use in multiple worksheets
 
I agree that the value of the cell makes a perfectly good €śGlobal variable€ť.
I dont see any advantage to the function and I would not bother with the
range name. The following is an example of how I might do it:

Sub testit2()

Dim strMode As String

strMode = ThisWorkbook.Worksheets("First Sheet").Range("A1").Value
If strMode = "test" Then
'Do what ya gotta do.
End If
If strMode = "Live" Then
'Do what ya don't gotta do.
End If

End Sub

I like the blnHasRun routine that Jim posted but would note two things:

1) Each time the workBOOK is opened it will be reset to False and run the
routine the first time the workSHEET is activated. If that is not desirable
you could use the value of a cell in the worksheet as the variable.

2) The code will need to be copied to each worksheet for which you want it
to apply.

I hope this helps.

Tom



All times are GMT +1. The time now is 10:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com