"Ambiguous name detected: Worksheet_Change" when adding 2 change events codes on the same sheet

charliemike9285

New Member
Joined
Jan 21, 2023
Messages
14
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Web
Hello, I am very new to VBAs and have figured out how to do these two functions separately but not how to combine them so they will both work on one sheet.
Putting them both on the same Project sheet I get the error message: Ambiguous name detected: Worksheet_Change (See image below)
My primary drop-down list is in Column F and my dependent drop down is in column H. The rows for the table are 2:100.
Any help would be greatly appreciated, thanks!

First change event is to Make multiple selections in a drop-down list (Column H):

Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)

Dim Oldvalue As String

Dim Newvalue As String

Application.EnableEvents = True

On Error GoTo Exitsub

If Not Intersect(Target, Range("H:H")) Is Nothing Then

If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then

GoTo Exitsub

Else: If Target.Value = "" Then GoTo Exitsub Else

Application.EnableEvents = False

Newvalue = Target.Value

Application.Undo

Oldvalue = Target.Value

If Oldvalue = "" Then

Target.Value = Newvalue

Else

If InStr(1, Oldvalue, Newvalue) = 0 Then

Target.Value = Oldvalue & ", " & vbNewLine & Newvalue

Else:

Target.Value = Oldvalue

End If

End If

End If

End If

Application.EnableEvents = True

Exitsub:

Application.EnableEvents = True

End Sub



Second change event is to Reset Dependent Drop-down for entire column (Column H):

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 6 Then 'Column F

If Target.Row >= 2 And Target.Row <= 100 Then

Cells(Target.Row, 8) = "Please Select..."

End If

End If

End Sub


See below :

1674290262560.png


Again these codes work separately, but I don't know how to make it so both codes will work on the same sheet.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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