+ Reply to Thread
Results 1 to 8 of 8

Error with chart using vba

  1. #1
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Error with chart using vba

    Hi,
    Can anyone give me an idea whats happening here?

    Part of my code copies a sheet, inserts it before a worksheet with a chart on it
    It then errors before renaming the new sheet
    I cant understand why it is causing the error

    Please Login or Register  to view this content.
    error appears in worksheets("Charts") for the highlighted code
    Please Login or Register  to view this content.
    it gives runtime error 91
    Object variable or with block variable not set
    In debug there is a value in ChartName
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Error with chart using vba

    Do you have an EndIf after the EndWith ??
    Elegant Simplicity............. Not Always

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Error with chart using vba

    There is no leading . in front of ChartTitle.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Error with chart using vba

    Yes there is,
    All i can think of is when i insert the new sheet, its activates the worksheet with the embedded chart and causes the combobox1 change event to occur, but i cant understand why it errors. the combobox1 code works perfectly to update the chart with different data based on dropdown value.
    here is the full code from the offending worksheet that errors. I have ammended it slightly and now it errors at
    .
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Error with chart using vba

    Not in your first post there is not.
    How can we guess what the error is if you post code that is different to the code you are using??

    Post an example, rather than snippets of incorrect code.

  6. #6
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Error with chart using vba

    Thanks Andy,
    there is a . in front, however i accidently deleted it when changing the font colour in the thread.

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error with chart using vba

    perhaps avoid activating
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  8. #8
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Error with chart using vba

    Thanks JP, that worked.
    I tried that earlier, but for some reason i was getting an error.
    Thinking about it i still had the chart.activate line still in, but change the with part.

    All sorted now, so thanks again.

+ 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