Using Variables across the whole project

llan_man

New Member
Joined
Nov 6, 2005
Messages
45
Hi

I've declared some public variables as listed below at the start of my project module. Each one is set to a value within a cell on a worksheet and is fixed for the whole project whilst the user is using it and they only change when a new user logs in. However when I try to use them within my project they don't hold the value that I assign to them. Am I using the right syntax?


Code:
Public pcno, pc_name, division_name As String
Public pcm_name, pcm_username, pcm_email As String
Public od_name, od_username, od_email As String
Public file_name, file_path, status_name As String
Public current_user, authority As String
Public status_value As Integer

Thanks

Harv
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Do you want to declare them as static instead? Public lets you use the variable across modules, but doesn't retain the assigned values across calls. Static does retain the values...
 
Upvote 0
Also note that
Code:
Public pcno, pc_name, division_name As String
will not do what you think.

It will declare division_name as a String, but pcno and pc_name will be declared as variant. In order to declare all three as strings, you would need to do this:
Code:
Public pcno As String, pc_name As String, division_name As String
 
Upvote 0
When you declare several variables on one line only the last one takes on the type you specify:

ie

Public pcno, pc_name, division_name As String

pcno is defined as a variant
pc_name = varaint
division_name = string
 
Upvote 0
Oaktree

Thanks

How and where should I use static and at what point do I assign the values to these variables.

Thanks

Harv
 
Upvote 0

Forum statistics

Threads
1,214,773
Messages
6,121,460
Members
449,033
Latest member
Kcolwell16

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