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?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,188
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
It sounds like you probably have that variable declared again, either at module level in module 2 or at procedure level.
 

AnyOldName

New Member
Joined
May 18, 2019
Messages
8
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.
 

Forum statistics

Threads
1,078,516
Messages
5,340,880
Members
399,397
Latest member
VolodimiirSr

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top