+ Reply to Thread
Results 1 to 3 of 3

Chart Objects Error

  1. #1
    Bill
    Guest

    Chart Objects Error

    Hello,
    I have two or more chart objects on worksheet that I want to delete before I
    rebuild them. I am using the following code to do that:

    Nchobj = ActiveSheet.ChartObjects.Count
    For i = 1 To Nchobj
    ActiveSheet.ChartObjects(i).Delete
    Next i
    Exit For

    The first one deletes OK. The second chart object generates this message:

    Unable to get ChartObjects property of the Worksheet class. On debug, it
    goes to the activesheet.chartobjects(i).delete line.

    Any ideas? Thanks.

    Bill



  2. #2
    Dave Peterson
    Guest

    Re: Chart Objects Error

    I'm not sure why you have that "exit for", but if you start at the highest
    number and work down, it helps:

    Nchobj = ActiveSheet.ChartObjects.Count
    For i = Nchobj to 1 step -1
    ActiveSheet.ChartObjects(i).Delete
    Next i

    Or if you just delete the first one (delete the first, the second becomes the
    new first, etc, etc, etc)

    Nchobj = ActiveSheet.ChartObjects.Count
    For i = 1 To Nchobj
    ActiveSheet.ChartObjects(1).Delete
    Next i




    Bill wrote:
    >
    > Hello,
    > I have two or more chart objects on worksheet that I want to delete before I
    > rebuild them. I am using the following code to do that:
    >
    > Nchobj = ActiveSheet.ChartObjects.Count
    > For i = 1 To Nchobj
    > ActiveSheet.ChartObjects(i).Delete
    > Next i
    > Exit For
    >
    > The first one deletes OK. The second chart object generates this message:
    >
    > Unable to get ChartObjects property of the Worksheet class. On debug, it
    > goes to the activesheet.chartobjects(i).delete line.
    >
    > Any ideas? Thanks.
    >
    > Bill


    --

    Dave Peterson

  3. #3
    Vic Eldridge
    Guest

    RE: Chart Objects Error

    Hi Bill,

    The simplest way would have to be ActiveSheet.ChartObjects.Delete

    Regards,
    Vic Eldridge



    "Bill" wrote:

    > Hello,
    > I have two or more chart objects on worksheet that I want to delete before I
    > rebuild them. I am using the following code to do that:
    >
    > Nchobj = ActiveSheet.ChartObjects.Count
    > For i = 1 To Nchobj
    > ActiveSheet.ChartObjects(i).Delete
    > Next i
    > Exit For
    >
    > The first one deletes OK. The second chart object generates this message:
    >
    > Unable to get ChartObjects property of the Worksheet class. On debug, it
    > goes to the activesheet.chartobjects(i).delete line.
    >
    > Any ideas? Thanks.
    >
    > Bill
    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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