It would be simpler to adjust your second macro to accept an incoming parameter so you could tell it what "cell" to run the macro against. Then when you CALL that macro, you send it that parameter at the same time:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C1:C500")) Is Nothing Then
Call Macro1(Intersect(Target, Range("C1:C500")))
End If
End Sub
Private Sub Macro1(Target As Range)
If Target.Value <> "" Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Accounts"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Cell Validated"
.InputMessage = ""
.ErrorMessage = "Cell validated.Select from dropdown list."
.ShowInput = True
.ShowError = True
End With
Else
Target.Validation.Delete
End If
End Sub
Further, this code so far only works if the user never edits more than one cell at a time. You could make the macro work on ALL the cells in the target range even if you changed a bunch at once by adding a loop:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C1:C500")) Is Nothing Then
Call AddValidation(Intersect(Target, Range("C1:C500")))
End If
End Sub
Private Sub AddValidation(Target As Range)
Dim Cell As Range
For Each Cell In Target
If Cell.Value <> "" Then
With Cell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Accounts"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Cell Validated"
.InputMessage = ""
.ErrorMessage = "Cell validated.Select from dropdown list."
.ShowInput = True
.ShowError = True
End With
Else
Cell.Validation.Delete
End If
Next Cell
End Sub
Bookmarks