New run time errors in older code 1004, 424, -2147024809 (80070057)

Neil Humphries

New Member
Aug 1, 2018
Windows 10, Excel 2016 The code is in a Module.

Three years ago, this code worked. Now it throws errors. Thetext of the error messages is different from that in the other threads I have seen with thesame error codes.

The code attempts to locate a button and delete it. There isonly one button per worksheet.

DeleteShapesByCaption "Create a new Schedule of Valuestab", wSht

Sub DeleteShapesByCaption( _
ByVal Caption AsString, _
Optional ByVal WSAs Worksheet = Nothing)
Dim Shp As Shape
If WS Is NothingThen Set WS = ActiveSheet
For Each Shp InWS.Shapes
'What kind ofshape is it?
Select CaseShp.Type
'May be acommandbutton
IfShp.OLEFormat.Object.Object.Caption = Caption Then
Shp.Delete 'This is where the error occurs
End If
Exit For
'May be abutton
IfShp.OLEFormat.Object.Caption = Caption Then Shp.Delete
End Select
End Sub

The error always occur at Shp.Delete
RTE 404 Object Required
RTE -2147024809 (80070057) The specified value is out ofrange

The workbook has a worksheet which is a template. Once thetemplate is filled in, it is copied for month 1. After the month 1 sheet iscompleted, the create a new sheet button is clicked to create a new sheet formonth 2 and the create a new sheet button is supposed to be removed from themonth 1 sheet. Each sheet only has one button.

I have used debug.print to confirm that the activesheet isthe previous month's sheet.

I have a version which moves from the back of the shapes collection to the front, but I still get the same -2147024809 (80070057) run time error with the same msg text.

This code worked properly in 2015. I have modified cellformulae to reflect changes in legislation, but I don't think those changes arerelevant because now even the 2015 workbook produces the errors.

The code executes as expected in creating the month 1 sheet.The only difference is that the create a new sheet button is not deleted from thetemplate page.

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...