Public variable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

using vba in excell how do I create a variable in one work sheet so that it
can be seen by all the other worksheets in the same workbook. I have tried
public x as interger but this does not seem to work.
 
You need to declare the variable in a regular code module, NOT
the worksheet's code module. However, if you do declare it in a
sheet's code module, you can refer to it with the worksheet's
codename as a qualifier. E.g.,

[in Sheet1]
Public MyVar As Long

[in Sheet2]
Sheet1.MyVar = 123


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
spent a long time trying to work out why it would not work, so easy when you
know how, can you recommend a good book on vba
thank you
--
Jack Allen


Chip Pearson said:
You need to declare the variable in a regular code module, NOT
the worksheet's code module. However, if you do declare it in a
sheet's code module, you can refer to it with the worksheet's
codename as a qualifier. E.g.,

[in Sheet1]
Public MyVar As Long

[in Sheet2]
Sheet1.MyVar = 123


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




Jack said:
using vba in excell how do I create a variable in one work
sheet so that it
can be seen by all the other worksheets in the same workbook. I
have tried
public x as interger but this does not seem to work.
 
I would recommend going to the book store and look for Chip as the author..

--
Don Guillett
SalesAid Software
(e-mail address removed)
Jack said:
spent a long time trying to work out why it would not work, so easy when
you
know how, can you recommend a good book on vba
thank you
--
Jack Allen


Chip Pearson said:
You need to declare the variable in a regular code module, NOT
the worksheet's code module. However, if you do declare it in a
sheet's code module, you can refer to it with the worksheet's
codename as a qualifier. E.g.,

[in Sheet1]
Public MyVar As Long

[in Sheet2]
Sheet1.MyVar = 123


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




Jack said:
using vba in excell how do I create a variable in one work
sheet so that it
can be seen by all the other worksheets in the same workbook. I
have tried
public x as interger but this does not seem to work.
 
I don't think Chip has written any books, a peek at his webpage would be a
good way to start learning about VBA

http://www.cpearson.com/excel/ExcelPages.htm


if books for beginners I would suggest something by John Walkenbach (excel
VBA programming for dummies), for intermediate and power VBA also John
Walkenbach (Power programming with VBA) for people who are already advanced
in VBA I would suggest the trio Stephen Bullen, Rob Bovey, John Green and
their "Professional Excel Development" book

--

Regards,

Peo Sjoblom

Northwest Excel Solutions

www.nwexcelsolutions.com

(remove ^^ from email address)

Portland, Oregon




Don Guillett said:
I would recommend going to the book store and look for Chip as the author..

--
Don Guillett
SalesAid Software
(e-mail address removed)
Jack said:
spent a long time trying to work out why it would not work, so easy when
you
know how, can you recommend a good book on vba
thank you
--
Jack Allen


Chip Pearson said:
You need to declare the variable in a regular code module, NOT
the worksheet's code module. However, if you do declare it in a
sheet's code module, you can refer to it with the worksheet's
codename as a qualifier. E.g.,

[in Sheet1]
Public MyVar As Long

[in Sheet2]
Sheet1.MyVar = 123


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




using vba in excell how do I create a variable in one work
sheet so that it
can be seen by all the other worksheets in the same workbook. I
have tried
public x as interger but this does not seem to work.
 
Back
Top