I have a column (G) in my excel sheet that has a drop down list using data validation. I want to be able to choose multiple options from this list. I copied and used the code from this YouTube video
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$A$10" Or Target.Address = "$D$10" 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
As is in the video, the line that would need changing is:
If Target.Address = "$A$10" Or Target.Address = "$D$10" Then
The code works fine when I apply it to say $G$300, but need to apply it to all of column G except G1 and G2 and can't seem to work out how to do that. Thanks for your help.
CodePudding user response:
Try the following instead:
If Not (Intersect(Target, Range("G3:G" & Rows.Count)) Is Nothing) Then