Help with variable declarations

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
539
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a macro which runs and loads a user form towards the end of the routine. There is a variable which gets set before the form is displayed which then shows up as empty when the user form is loaded. When the user form is unloaded and the macro resumes, I can see the variable once again has the value assigned. What do I need to change to make the variable stick while the user form is displayed? I am trying to use it while the user form is displayed to the user.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
How have you got it declared now and where/when/how are you giving it a value?
 
Upvote 0
Hi Norie,

I have it declared "above" the module in the General/Declarations section. There are three separate subroutines in the module, a primary and two secondary. There is a T/F check in the primary which determines which of the secondary routines is called and that is where the variable gets set. It is used both in the secondary sub and when processing returns to the primary sub.

I have tried with it set as Dim varname As String and also Public varname As String, both in the General/Declarations section.

I double-checked to make sure it is only declared one time. I have also double-checked to make sure it is only set one time. I have basically the same setup in two other files but it doesn't work with this new file.
 
Upvote 0
Have you considered not using public variables for this?

I think I might have actually suggested that before.

What exactly are you using this variable for?

You mention it gets some sort of check in a 'primary sub' then it's used in another sub.

Have you considered that it might be getting changed in the sub that's called?
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

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