Redefining Public Variables

kmh6278

Board Regular
Joined
Mar 7, 2006
Messages
52
I have a number of variables being declared as "Public" so that their values hold through a number of sub procedures. For one, I need a few of the values to change. Originally I thought I could do the following:

Start_Row = 3
Call ShadeRow

Start_Row = 5
Call ShadeRow2

Basically, setting the value of Start_Row to 3, calling ShadeRow, then resetting the value of Start_Row to 5 and calling ShadeRow2.

Is there a way to accomplish this? I'm trying to limit the amount of variables that exist for easier editing/flexibility.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You can pass a parameter through the Sub:

Code:
Sub ShadeRow2(Start_Row as integer)
'code for ShadeRow2
End Sub
Then you can when you call it:

Code:
Call ShadeRow2(3)
Call ShadeRow2(5)
Hope that helps.
 
Upvote 0
Is using public variables actually conducive to 'easier editing/flexibility'?
 
Upvote 0
The idea is that the code will be able to be used by multiple people, for multiple projects by tweaking a limited number of variables. Reports will be run using a collection of procedures which refer to the same variables, however, their values will be able to be changed from procedure to procedure. The main procedure will call the others so that the user only has to make edits in one area. As such, I need the variables to exist in all procedures and research led me to declaring them as "public."
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,142
Members
448,551
Latest member
Sienna de Souza

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top