I am fairly new to VBA and have created a file where the VBA code seems excessive, due to repetition
My feeling is that it can be optimised, but I am not sure of the best way to do it, so I was looking for some guidance on how it could be rewritten.
Below is a part of the code (to update validation input messages) which uses the Worksheet Change event & as you can see, this is the same code repeated, but with varying targets & output values
Any advise would be gratefully received. Thanks
My feeling is that it can be optimised, but I am not sure of the best way to do it, so I was looking for some guidance on how it could be rewritten.
Below is a part of the code (to update validation input messages) which uses the Worksheet Change event & as you can see, this is the same code repeated, but with varying targets & output values
VBA Code:
If Target.Address = "$G$2" Then
With Worksheets("Gantt Chart").Range("$F$3").Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.InputTitle = "Comment"
.InputMessage = Sheet3.Range("$G$2").Value
End With
End If
If Target.Address = "$G$3" Then
With Worksheets("Gantt Chart").Range("$F$4").Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.InputTitle = "Comment"
.InputMessage = Sheet3.Range("$G$3").Value
End With
End If
If Target.Address = "$G$4" Then
With Worksheets("Gantt Chart").Range("$F$5").Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.InputTitle = "Comment"
.InputMessage = Sheet3.Range("$G$4").Value
End With
End If
If Target.Address = "$G$5" Then
With Worksheets("Gantt Chart").Range("$F$6").Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.InputTitle = "Comment"
.InputMessage = Sheet3.Range("$G$5").Value
End With
End If
Any advise would be gratefully received. Thanks