Public Variables -Can They be Referred to by Subs in Multiple Modules?

AnyOldName

New Member
Joined
May 18, 2019
Messages
8
I had hoped to be able to declare a variable as public in one module, assign a value to it then refer to it in other modules but as soon as I try to use it in a different module I'm getting "Compile error: Ambiguous name detected"

Module 1 Highlights
Public Var_DRPS_Code_Version As Variant

This variable is given a value from a cell on one of the sheets and can be used/referred to without problem in Module 1

Module 2
As soon as I try to refer to the variable, I get the aforementioned error message.

I hope someone can advise me on this. This code is to carry out some very repetitive tasks in updating a large data table in Excel, there are a few frequently referred to values so I had planned on reading them into variables that can then be referred to by the rest of the code as they are needed. I can come up with a work around for this particular variable but there are a few others that have evolving values and will make things a bit more complex. Should I be writing all of these values into cells somewhere then just reading them back into the code as they are needed?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
It sounds like you probably have that variable declared again, either at module level in module 2 or at procedure level.
 
Upvote 0
Thanks, I thought I had already checked for that but I'd forgotten that I had some old code in a now unused module. It hadn't created a problem until I tried to use the variable in multiple modules.
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,467
Members
448,965
Latest member
grijken

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