charliemike9285
New Member
- Joined
- Jan 21, 2023
- Messages
- 14
- Office Version
- 365
- Platform
- Windows
- MacOS
- 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 :
Again these codes work separately, but I don't know how to make it so both codes will work on the same 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 :
Again these codes work separately, but I don't know how to make it so both codes will work on the same sheet.