Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is VBA saying that it has found an 'ambiguous name'?

Tags:

excel

vba

When compiling some code (declarations shown below) I get the error message 'Compile Error: Ambiguous name detected. SixTables'. I have looked here and elsewhere but cannot find anything that matches my problem. What appear to be the most common causes of this error, declaring two variables with identical names or giving the same name to a function and the sub that it is called from, do not apply. And yes, I know I could just change the name to something the system was happy with, but (1) I wouldn't learn what I'm doing wrong, and (2) I chose that name for a reason - it fits its purpose exactly :-)

Option Explicit

Dim ArmOfService As Byte
Dim CharacterNumber As Long
Dim CurrentTerm As Byte
Dim DecorationRollMade As Byte
Dim DecorationRollNeeded As Byte
Dim DiceSize As Byte
Dim GenAssignment
Dim GenAssignmentSwitchInt As Byte
Dim GenAssignmentSwitchOff As Byte
Dim iLoopControl
Dim jLoopControl
Dim kLoopControl
Dim LineIncrement As Integer
Dim lLoopControl
Dim Merc(100)
Dim NoOfDice As Byte
Dim OfficerPromotion(63 To 78) As Byte
Dim PromotionRollMade As Byte
Dim PromotionRollNeeded As Byte
Dim Roll As Byte
Dim SkillColumn
Dim SixTables
Dim SpecAssignmentSwitchEnd As Byte
Dim SurvivalRollMade As Byte
Dim SurvivalRollNeeded As Byte
Dim TechLevel As Byte
Dim Temp As Integer
Dim Term As Byte
Dim TestCount
Dim UnitAssignment
Dim WhichTable
Dim Year As Byte

EDIT: I'm so embarrassed that I can hardly bring myself to explain what the problem was. I knew I hadn't duplicated a name, since I was only using it once - as a function! Thanks all for your help, I'm now going to go and hide my face in shame...

like image 862
Kevin Pooley Avatar asked Nov 27 '13 23:11

Kevin Pooley


People also ask

How do I fix an ambiguous name in Excel?

This error has the following causes and solutions: More than one object in the same scope may have elements with the same name. In this case, you must change one of the names because qualification with a common module name would not resolve the ambiguity.

What is an ambiguous name?

What makes a name ambiguous? Simply put, and ambiguous name is a name that might reasonably be interpreted as referring to more than one possible chemical structure. Two of the most important phrases in that description are "reasonably" and "more than one".

How do I fix a VBA error in Excel?

To do this, click on 'Tools' and then click on 'Options'. In the options dialog box, make sure that the 'Auto Syntax Check' option is enabled. If the 'Auto Syntax Check' option is disabled, VBA will still highlight the line with the syntax error in red, but it will not show the error dialog box.


1 Answers

From MSDN :

  1. More than one object in the same scope may have elements with the same name.

Module-level identifiers and project-level identifiers (module names and referenced project names) may be reused in a procedure, although it makes programs harder to maintain and debug. However, if you want to refer to both items in the same procedure, the item having wider scope must be qualified. For example, if MyID is declared at the module level of MyModule , and then a procedure-levelvariable is declared with the same name in the module, references to the module-level variable must be appropriately qualified:

Dim MyID As String 
Sub MySub 
MyModule.MyID = "This is module-level variable" 
Dim MyID As String 
MyID = "This is the procedure-level variable" 
Debug.Print MyID 
Debug.Print MyModule.MyID 
End Sub 
  1. An identifier declared at module-level conflicts with a procedure name.

For example, this error occurs if the variable MyID is declared at module level, and then a procedure is defined with the same name:

Public MyID 
Sub MyID 
. . . 
End Sub 
like image 178
Kairan Avatar answered Nov 11 '22 02:11

Kairan