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
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
7,988
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...
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,387
Office Version
  1. 365
Platform
  1. Windows
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
 

MichaelRo

Well-known Member
Joined
Jun 7, 2004
Messages
549
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
 

llan_man

New Member
Joined
Nov 6, 2005
Messages
45
Oaktree

Thanks

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

Thanks

Harv
 

Watch MrExcel Video

Forum statistics

Threads
1,118,228
Messages
5,571,012
Members
412,353
Latest member
SofiaV
Top