+ Reply to Thread
Results 1 to 5 of 5

How can I use VBA to create multiple pie charts from a series of data

Hybrid View

  1. #1
    Registered User
    Join Date
    05-24-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    1

    Post How can I use VBA to create multiple pie charts from a series of data

    Hi

    I need help creating multiple pie charts from a series of data, Basically there are 2 weekly totals that I need to make into a weekly pie chart, is there anyway I can do this without creating a chart for each individual week manually and having them produced automatically with a vba.

    It would be a great help if anyone could help me.

    Thanks

    John
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: How can I use VBA to create multiple pie charts from a series of data

    Maybe something like this...

    Option Explicit
    
    Sub test()
    
        Dim ChrtObj As ChartObject
        Dim MySeries As Series
        Dim LeftPos As Long
        Dim TopPos As Long
        Dim LastCol As Long
        Dim i As Long
    
        LeftPos = 50
        TopPos = 75
    
        LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
        
        For i = 2 To LastCol
            Set ChrtObj = ActiveSheet.ChartObjects.Add(LeftPos, TopPos, 360, 215)
            With ChrtObj.Chart
                .ChartType = xlPie
                Set MySeries = .SeriesCollection.NewSeries
                With MySeries
                    .XValues = Range(Cells(2, "a"), Cells(3, "a"))
                    .Values = Range(Cells(2, i), Cells(3, i))
                    .Name = Cells(1, i).Value
                    .ApplyDataLabels Type:=xlDataLabelsShowValue
                    .DataLabels.NumberFormat = "#,##0"
                End With
                LeftPos = .Parent.Left + .Parent.Width + 15
            End With
        Next i
        
    End Sub

  3. #3
    Registered User
    Join Date
    10-30-2009
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    60

    Re: How can I use VBA to create multiple pie charts from a series of data

    Sorry for the old thread revival (hope it's ok to do this?)

    If the data is stored in rows rather than columns, how & where would the code above need to be changed?

    Thanks in advance

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

    Re: How can I use VBA to create multiple pie charts from a series of data

    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]

  5. #5
    Registered User
    Join Date
    10-30-2009
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    60

    Re: How can I use VBA to create multiple pie charts from a series of data

    Sorry, I'll start a new thread.

+ 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