VBA: Public variable not carrying between modules (help!)

hellfire45

Active Member
Joined
Jun 7, 2014
Messages
462
Hi guys,

So I have some VBA. I am declaring a public variable as integer in module 1 and lets say for example in module 1 it is declared as a value = 19.

Code:
Public batch_audit_col As Integer

Code:
batch_audit_col = Application.Match("BATCH1", Dash.Rows("1:1"), 0)

Then module 2 starts and I do not re-declare it and I apparently don't need to because VBA Doesn't error and ask me to. So I expect the value will still be 19. However, its not, its equal to zero. Not blank, but zero.


So if I hit a break point in the code and check the value of the variable in each module module 1 will say 19 and module 2 says 0. I need both modules to know that the variable is equal to 19.



Why is this happening? Thanks for the help.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Double check that you are re-declaring it anywhere (including in code) & also check that you are not re-assigning a value
 
Upvote 0
Double check that you are re-declaring it anywhere (including in code) & also check that you are not re-assigning a value
A good way to do that is to use the built-in Find functionality (CTRL-F), and search for that variable name across the "Current Project".
It should then cycle you through all instances of that word appearing in your code.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,165
Members
448,870
Latest member
max_pedreira

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