Compile error: Ambiguous name detected

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
PHP:
'==========================
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
  Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
Cancel = True
Set cboTemp = ws.OLEObjects("TempCombo")
  On Error Resume Next
  With cboTemp
  'clear and hide the combo box
    .ListFillRange = ""
    .LinkedCell = ""
    .Visible = False
  End With
On Error GoTo errHandler
  If Target.Validation.Type = 3 Then
    'if the cell contains a data validation list
    Application.EnableEvents = False
    'get the data validation formula
    str = Target.Validation.Formula1
    str = Right(str, Len(str) - 1)
    With cboTemp
      'show the combobox with the list
      .Visible = True
      .Left = Target.Left
      .Top = Target.Top
      .Width = Target.Width + 5
      .Height = Target.Height + 5
      .ListFillRange = ws.Range(str).Address
      .LinkedCell = Target.Address
    End With
    cboTemp.Activate
  End If
  
errHandler:
  Application.EnableEvents = True
  Exit Sub

End Sub
'=========================================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet

Set cboTemp = ws.OLEObjects("TempCombo")
  On Error Resume Next
If cboTemp.Visible = True Then
  With cboTemp
    .Top = 10
    .Left = 10
    .ListFillRange = ""
    .LinkedCell = ""
    .Visible = False
    .Value = ""
  End With
End If

errHandler:
  Application.EnableEvents = True
  Exit Sub

End Sub
'====================================
'Optional code to move to next cell if Tab or Enter are pressed
'from code by Ted Lanham
Private Sub TempCombo_KeyDown(ByVal _
        KeyCode As MSForms.ReturnInteger, _
        ByVal Shift As Integer)
    Select Case KeyCode
        Case 13 'Enter
            ActiveCell.Offset(0, 1).Activate
        Case Else
            'do nothing
    End Select
End Sub
'====================================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$Z$3:$AA$3" Then
Call GoToMatch
End If
End Sub
'====================================


Compile error:
Ambiguous name detected: Worksheet_SelectionChange

this error occurs and higlights the line Private Sub Worksheet_SelectionChange(ByVal Target As Range) which belongs to the last Private Sub that is:-
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$Z$3:$AA$3" Then
Call GoToMatch
End If
End Sub

any help will be appreciated...
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You can't have two macros for the same event on the same sheet, combine them in to one like so:

Rich (BB code):
'========================================= 
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
Dim str As String 
Dim cboTemp As OLEObject 
Dim ws As Worksheet 
If Target.Address = "$Z$3:$AA$3" Then'<-----Added bit
Call GoToMatch '<-----Added bit
else'<-----Added bit
Set ws = ActiveSheet 
 
Set cboTemp = ws.OLEObjects("TempCombo") 
On Error Resume Next 
If cboTemp.Visible = True Then 
With cboTemp 
.Top = 10 
.Left = 10 
.ListFillRange = "" 
.LinkedCell = "" 
.Visible = False 
.Value = "" 
End With 
End If 
End If '<-----Added bit
errHandler: 
Application.EnableEvents = True 
Exit Sub 
 
End Sub 
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,934
Messages
6,175,491
Members
452,649
Latest member
mr_bhavesh

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