![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Posts: 42
|
Dear all,
I am having difficulty with the whole idea of setting variables. I want to declare a variable in one user form that then gets used in a different user form. I have tried making sure all subs are not private, I have tried declaring the variable in the option explicit section. I have tried declaring it at the start of a sub etc. I have been told to try dim myvariable as public, that doesn't work, I have tried public myvariable and public dim myvariable, I've tried the help files - I'm going loopy! Each time I run the routines the variable shows up in the locals window but then later in a different form the variable when called is empty. Can anybody explain how I keep a variable in memeory to use anywhere within a workbook/form Many thanks Andy |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
The approach I use with multiple forms, which works for me, but probably isn't the 'best' way, is to put all my variable handling procedures into a standard module and have events from within the form module call procedures from the standard module. In this way you can have all your variables declared in one or more standard modules which gets round the probelm of variables losing scope. Note that if you adopt this approach, from within the standard module you need to refer to controls on your userforms explicitly ie
Form1.TextBox1.Text rather than just TextBox1.Text |
|
|
|
|
|
#3 |
|
New Member
Join Date: Feb 2002
Posts: 42
|
Dear Mudface
thanks for both your replies, will get to work on them shortly, although I'm still not sure about the variables issue....lol |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|