Reputation: 1
I have been trying to have multiple selections from a drop-down list. I was able to make it work for specific cells, but I can't figure out a way to make the formula work for the entire row.
Here is my code.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$D$2" Or Target.Address = "$D$3" Or Target.Address = "$D$4" 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
I tried using Target.Address = Range"$D$2:$D$13" with varying () and "" and it didn't work. I want to be able to apply the multiple selections to the entire row in my table in one formula.
Upvotes: 0
Views: 53
Reputation: 8769
This might work, by checking column number instead of A1 address of the target.
'
'If target.Address = "$D$2" Or target.Address = "$D$3" Or target.Address = "$D$4" Then
'
If target.Cells.Count = 1 And target.Column = 4 Then
Upvotes: 0