Good Afternoon,
I'm new to VBA codes and need some help. I would like to have the two code below operating on the same worksheet. I've got the first one working but not sure how to add the second. Some help would be greatly appreciate.
Code 1)
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from https://trumpexcel.com
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$F$21" Or Target.Address = "$E$50" Or Target.Address = "$F$53" Or Target.Address = "$E$56" Or Target.Address = "$E$62" Or Target.Address = "$D$66" 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 & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
Code 2)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Select Case Target.Value
Case "Yes"
ActiveSheet.Rows("3:5").Hidden = False
Case "No"
ActiveSheet.Rows("3:5").Hidden = True
End Select
End If
End Sub
I'm new to VBA codes and need some help. I would like to have the two code below operating on the same worksheet. I've got the first one working but not sure how to add the second. Some help would be greatly appreciate.
Code 1)
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from https://trumpexcel.com
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$F$21" Or Target.Address = "$E$50" Or Target.Address = "$F$53" Or Target.Address = "$E$56" Or Target.Address = "$E$62" Or Target.Address = "$D$66" 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 & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
Code 2)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Select Case Target.Value
Case "Yes"
ActiveSheet.Rows("3:5").Hidden = False
Case "No"
ActiveSheet.Rows("3:5").Hidden = True
End Select
End If
End Sub