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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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,376
Messages
6,119,180
Members
448,871
Latest member
hengshankouniuniu

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