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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,842
Messages
5,766,738
Members
425,376
Latest member
Bradleyckx

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
Top