+ Reply to Thread
Results 1 to 7 of 7

VBA Loop through sheets and create charts

  1. #1
    Registered User
    Join Date
    11-04-2009
    Location
    Augustow, Poland
    MS-Off Ver
    Excel 2003
    Posts
    3

    VBA Loop through sheets and create charts

    Hi everyone,

    I need to write a macro that will run through all worksheets in a given file, creating charts for each of them.

    The columns in each of the files/worksheets are always the same, but the number of rows vary. Blank cells are scattered here and there.

    I wrote the following VBA script but it fails to work. I would appreciate advice.

    I have an extra question as well: I cannot understand why a chart is created in a new sheet and not as an object in the active one?

    Please Login or Register  to view this content.
    It is supported by two functions:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    Last edited by namche; 11-04-2009 at 07:54 AM.

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

    Re: VBA Loop through sheets and create charts

    Can you post example workbook so we can see the data layout. Also include an example of the chart.

    FYI. the code charts.add is for create a new chart sheet.
    If you want a chart object directly on the sheet then you need to use the add method of chartobjects

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    11-04-2009
    Location
    Augustow, Poland
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VBA Loop through sheets and create charts

    Hi Andy!

    Thanks for a quick reply. Your suggestion with chartobjects works - great!

    I prepared an example sheet with 5 rows (usually there is around 30, maximum around 100). I would be very obliged if you could have a look.

    Cheers,

    Radek
    Attached Files Attached Files

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

    Re: VBA Loop through sheets and create charts

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-04-2009
    Location
    Augustow, Poland
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VBA Loop through sheets and create charts

    Works beautifully! Thank you so much, I've spent hours trying to solve the problem :-)

  6. #6
    Registered User
    Join Date
    07-30-2012
    Location
    Norfolk, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: VBA Loop through sheets and create charts

    I am trying to create a similar loop but instead of going through different workbooks I want to create a chart for each line in my work book. Attached is a copy of the file. Thanks for your helpCoding practice.xls

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA Loop through sheets and create charts

    Petebmor,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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