I am having trouble understanding why I get a runtime error 1004 'Application-defined or object defined error' when my macro is triggered.
My file has 2 worksheets:
The macro uses the values highlighted in yellow from the "Data" worksheet, to populate the data validation input message for the cells circled in the "Overview" worksheet, when the user navigates from the Data worksheet to the Overview worksheet.
The runtime error occurs if the shape on the Overview worksheet has previously been selected, prior to navigating to the Overview worksheet.
Would appreciate any guidance on how this could be avoided.
Thank you
My file has 2 worksheets:
"Data" | "Overview" |
| The Project Overview header is a shape |
The macro uses the values highlighted in yellow from the "Data" worksheet, to populate the data validation input message for the cells circled in the "Overview" worksheet, when the user navigates from the Data worksheet to the Overview worksheet.
VBA Code:
Private Sub Worksheet_Deactivate()
For Targetrow = 2 To 6
TargetValue = Worksheets("Data").Range("G" & Targetrow)
With Worksheets("Overview").Range("F" & Targetrow + 2).Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator:=xlBetween
.InputTitle = "Comment"
.InputMessage = TargetValue
End With
TargetValue = Worksheets("Data").Range("I" & Targetrow)
With Worksheets("Overview").Range("G" & Targetrow + 2).Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator:=xlBetween
.InputTitle = "Original Target Date"
.InputMessage = TargetValue
End With
Next Targetrow
End Sub
The runtime error occurs if the shape on the Overview worksheet has previously been selected, prior to navigating to the Overview worksheet.
Would appreciate any guidance on how this could be avoided.
Thank you