+ Reply to Thread
Results 1 to 6 of 6

Run-time error '438': - trying to delete a chart but code is failing

  1. #1
    Forum Contributor
    Join Date
    08-03-2009
    Location
    Cary, NC
    MS-Off Ver
    Excel 2016
    Posts
    109

    Run-time error '438': - trying to delete a chart but code is failing

    I'm running the following the code:

    Please Login or Register  to view this content.
    The problem is with these two lines:

    Please Login or Register  to view this content.
    If I comment out these lines the code works fine. If I run it with these two lines, the first line deletes the chart but I get the error and it hangs up at that line. I have this procedure assigned to a button on a separate sheet. If I run it once (with those lines commented out) I have no problems. If I run it a second time (with the lines commented out), however, the first chart is still there and the second chart gets messed up. What I'm trying to do is delete the first chart before making the second one. How do I do this?
    Last edited by bishoposiris; 02-14-2016 at 06:13 PM. Reason: Solved

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Run-time error '438': - trying to delete a chart but code is failing

    Hi there,

    Try replacing part of your code with the following highlighted lines:

    Please Login or Register  to view this content.
    Obviously I don't have any data with which to fully test the code, but I seem to be able to create and delete "empty" graphs as required.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Forum Contributor
    Join Date
    08-03-2009
    Location
    Cary, NC
    MS-Off Ver
    Excel 2016
    Posts
    109

    Re: Run-time error '438': - trying to delete a chart but code is failing

    I did what you said and added the following code:

    Please Login or Register  to view this content.
    I get "Run-time error '1004': Application-defined or object-defined error" at this line:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Run-time error '438': - trying to delete a chart but code is failing

    Hi again,

    Did the worksheet contain a ChartObject (graph) when you ran the code?

    If you wish to run the routine when the worksheet contains no ChartObject (e.g. the first time the routine is run) you should add the following highlighted lines:

    Please Login or Register  to view this content.
    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  5. #5
    Forum Contributor
    Join Date
    08-03-2009
    Location
    Cary, NC
    MS-Off Ver
    Excel 2016
    Posts
    109

    Re: Run-time error '438': - trying to delete a chart but code is failing

    I ended up solving this problem with the following code:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Run-time error '438': - trying to delete a chart but code is failing

    Hi again,

    Many thanks for that interesting and useful feedback - it just goes to show that in Excel there's always more than one way to skin a cat!

    Thanks also for the Reputation increase - much appreciated

    Best regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Run-time error '438': - trying to delete a chart on workbook close
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 03:30 PM
  2. [SOLVED] Run-time error '1004' - code failing when on a different sheet
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-10-2016, 12:48 PM
  3. [SOLVED] Macros must be enabled code failing with Run Time Error 57121
    By leaning in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2016, 11:25 AM
  4. Cannot Publish Excel Pivot Chart - Run Time Error
    By crisb184 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2013, 07:04 AM
  5. Autofilter Macro Failing - Run-time error 91 - full macro code is attached
    By evamarie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-07-2013, 02:36 PM
  6. Run Time error due to event change code when I delete columns in file
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2012, 12:53 PM
  7. [SOLVED] Delete rows failing
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2011, 05:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1