declare & initialize a variable as global using vba

mike08

Board Regular
Joined
Oct 29, 2008
Messages
167
Hi experts,

Would u kindly let me know , how to declare&initialize a variable as Global in vba?
I have a variable ,
listGroup=Array("aaa","bbb","ccc")
now i am using this variable for 3 different functions. so what i am doing is wrote the same code to 3 functions, so how i can declare&initialize this variable as global and access to all functions.

Thanks for any help
 
Hi Nitin,
Thanks, i worked with query , showing error, i will explain what i need is,
In an excel I have 3 buttons, Downloads,Purchase & Lead time, and i have the following variables is common to these 3 buttons. So what i wrote these common variable are declared in the General declaration statement and these variables initialed in the workbook_Open() section.
Code:
' Code for general declaration
Public listGroup, listGroup1, listGroup2, mon
Public title1, title2, title3, title4, title5, title6, title7
'Code for initialization 
Private Sub Workbook_Open()
listGroup1 = Array("Associated", "Express Newspapers", "Independent")
listGroup2 = Array("Guardian Newspapers", "MGN", "News International", "Scotsman", "Telegraph")
listGroup = Array("Associated", "Express Newspapers", "Independent", "Guardian Newspapers", "MGN", "News International", "Scotsman", "Telegraph")
 mon = Array("Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
title1 = Array("Associated Newspapers Limited/Daily Mail Genral Trust/Scottish Daily Mail", "Associated Newspapers Ltd./Mail on Sunday/Live magazine (used to be Night and Day)", "Associated Newspapers Ltd/Daily Mail General Trust/Daily Mail Weekend Mag and Femail", "Associated Newspapers Ltd/Daily Mail General Trust/Mail on Sunday", "Associated Newspapers Ltd/Daily Mail General Trust/Mail on Sunday ADVERTISING", "Associated Newspapers Ltd/Mail on Sunday/You magazine", "Associated Newspapers Ltd/Scottish Mail on Sunday/", "London Lite/London Lite (separate newspapers)RF Editorial Client")
 title2 = Array("Northern and Shell/Express Newspaper Group/Daily Express", "Northern and Shell/Express Newspaper Group/Daily Star", "Northern and Shell/Express Newspaper Group/Saturday Express Magazine", "Northern and Shell/Express Newspaper Group/Star Magazine", "Northern and Shell/Express Newspaper Group/Sunday Express", "Northern and Shell/Express Newspaper Group/Sunday Express Magazine", "Northern and Shell/Express Newspaper Group/Take 5", "OK Magazine/Express Newspapers/")
 title3 = Array("Independent Newspaper", "Independent on Sunday")
 title4 = Array("Guardian News Media/The Guardian/ Guardian Unlimited / Observer/RF EDITORIAL CLIENT", "USA WEEKEND MAGAZINE")
 title5 = Array("MGN Limited/Sunday Mail/scottish daily record and sunday mail ltd", "The People/Trinity Mirror Group/MGN", "Trinity Mirror plc/MGN ltd/Take It Easy Magazine", "Trinity Mirror Plc/MGN/We Love Telly", "Trinity Mirror/Mgn Limited/Sunday mirror")
 title6 = Array("Scotsman//Scotman publications", "Scotsman//Scotman publications")
 title7 = Array("Telegraph/Stella Magazine/RF EDITORIAL CLIENT", "Telegraph/Sunday", "The Daily Telegraph")
End Sub
After that i clicked on any one of the button, showing error 'Type mismatch' in the above variables place.

Is there any other way to initialize the variables which will be accessed to all these buttons?
pls reply....
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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