Runtime error 1004 when shape is selected

scott_od

New Member
Joined
Jan 25, 2016
Messages
27
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:
"Data""Overview"
1634718821329.png
1634719011990.png

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.
1634719414527.png


Would appreciate any guidance on how this could be avoided.
Thank you
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top