“检测到模糊名称”

时间:2015-10-21 18:50:18

标签: excel vba excel-vba ambiguity

我目前遇到第二个子部分工作的问题。我有一个错误:

  

检测到的Ambigious名称:Worksheet_BeforeDoubleClick

我尝试更改第二个名称,但代码仍无效。这两个Subs都是单独工作,但只将它们放在一起工作。

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim HotArea As Range

Set HotArea = Range("C17,C21,C25,C29,C33,C42,C46,C50,C54,C58,C67,C71,C75,C83,C87,C91,C100,M17")
Set HotArea = Union(HotArea, Range("M21,M25,M29,M33,M42,M46,M55,M59,M69,M73,M82,M86,W17,W21,W25,W29,AG17,AG21,AG25,AG34"))
Set HotArea = Union(HotArea, Range("AG38,AG42,AG51,AG55,AG59,AG68,AG72,AG81,AG85,AG89,AG98,AG102,AG106,AG110,AG114,AQ17"))
Set HotArea = Union(HotArea, Range("AQ21,AQ30,AQ34,AQ43,AQ47,AQ51,AQ60,AQ64,BA17,BA21,BA25,BA29,BA33,BA37,BA46,BA50,BA54"))
Set HotArea = Union(HotArea, Range("BA58,BA62,BA71,BA75,BA79,BA89,BA93"))

If Not Intersect(Target, HotArea) Is Nothing Then
Select Case Target.Item(1)
Case ""
    Target = "P1"
    Target.Interior.ColorIndex = 3
Case "P1"
    Target = "P2"
    Target.Interior.ColorIndex = 6
Case "P2"
    Target = "P3"
    Target.Interior.ColorIndex = 50
Case "P3"
    Target = "P4"
    Target.Interior.ColorIndex = 23
Case Else
    Target = ""
    Target.Interior.ColorIndex = xlNone
End Select
Cancel = True
End If
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim HotArea As Range

Set HotArea = Range("C19,C23,C27,C31,C35,C44,C48,C52,C56,C60,C69,C73,C77,C85,C89,C93,C102,M19")
Set HotArea = Union(HotArea, Range("M23,M27,M31,M35,M44,M48,M57,M61,M71,M75,M84,M88,W19,W23,W27,W31,AG19,AG23,AG27,AG36"))
Set HotArea = Union(HotArea, Range("AG40,AG44,AG53,AG57,AG61,AG70,AG74,AG83,AG87,AG91,AG100,AG104,AG108,AG112,AG116,AQ19"))
Set HotArea = Union(HotArea, Range("AQ23,AQ32,AQ36,AQ45,AQ49,AQ53,AQ62,AQ66,BA19,BA23,BA27,BA31,BA35,BA39,BA48,BA52,BA56"))
Set HotArea = Union(HotArea, Range("BA60,BA64,BA73,BA77,BA81,BA91,BA95"))

If Not Intersect(Target, HotArea) Is Nothing Then

    'If the target cell is clear
    If Target.Interior.ColorIndex = xlNone Then
    'Then change the background to the specified color
    Target.Interior.ColorIndex = 4

'But if the target cell is already the specified color
    ElseIf Target.Interior.ColorIndex = 4 Then

    'Then change the background to the specified color
    Target.Interior.ColorIndex = 6

   'But if the target cell is already the specified color
    ElseIf Target.Interior.ColorIndex = 6 Then

    'Then change the background to the specified color
    Target.Interior.ColorIndex = 3

    'But if the target cell is already the specified color
    ElseIf Target.Interior.ColorIndex = 3 Then

    'Then change the background to the specified color
    Target.Interior.ColorIndex = 5

    'But if the target cell is already the specified color
    ElseIf Target.Interior.ColorIndex = 5 Then

    'Then change the background to the specified color
    Target.Interior.ColorIndex = x1None
End If
Cancel = True
End If
End Sub  

如何更改名称以便两者都有效?

1 个答案:

答案 0 :(得分:2)

代码模块中的所有过程都必须具有唯一的名称。

在这里,我从过程的第二个实例中取出代码并将其附加到第一个实例的底部:

[5, 3, 7, 2]
[2, 7, 3, 5]