Auto Create Charts from Different Rows in Excel

Ashberrie

New Member
Joined
Jul 5, 2018
Messages
1
Hello!

I'm very new to VBA and have managed to create most of what I need; but am stuck on the hardest part IMO - Looping through the rows to create each chart.

What I'm looking to achieve: Creating a chart for each row of data in my excel sheet. Each row of data has three years of monthly data; the chart needs to have January compared to January compared to January (and so on for each month). Each chart needs to be exported as a PDF into a specific folder then delete the chart. (I have 755 rows - yes, I know it's a lot of charts)

What I've been able to do: Create the chart in VBA for a single row.

Where I'm stuck: I don't know how to get it to loop through each row and create a chart for each row.

Here's the sample data I'm working with:
CategoryJanFebMarJanFebMarJanFebMar
A2958134218331074484
B38761754234313857109
C621242889377122694179
D77153351104687280117222
E71143321034381260108206
F621232889377022594178

<tbody>
</tbody>

This is the VBA code I have currently:
Code:
Sub ChartCreator()

'Create new Workbook
Workbooks.Add


'Add chart and define style
    Dim ChartSheet1 As Chart
    
    Set ChartSheet1 = Charts.Add
        With ChartSheet1
            .ChartType = xlColumnClustered
            .ChartStyle = 215
            .ChartColor = 10
            .HasDataTable = True
            .HasTitle = True
            .HasLegend = False
            .ChartTitle.Text = Workbooks("VBA Chart Creator.xlsm").Sheets("Sheet1").Range("A2")
            '.Name = Workbooks("VBA Chart Creator.xlsm").Sheets("Sheet1").Range("A2")
        End With


'1st year of data
    Set Series1 = ActiveChart.SeriesCollection.NewSeries
        With Series1
            .Name = "Year1"
            'Sets Vertical Axis/Data
            .Values = "='[VBA Chart Creator.xlsm]Sheet1'!B2:D2"
            'sets Horizontal Axis Label
            .XValues = "='[VBA Chart Creator.xlsm]Sheet1'!$B$1:$D$1"
        End With


'2nd year of data
    Set Series2 = ActiveChart.SeriesCollection.NewSeries
        With Series2
            .Name = "Year2"
            'Sets Vertical Axis/Data
            .Values = "='[VBA Chart Creator.xlsm]Sheet1'!E2:G2"
            'sets Horizontal Axis Label
            .XValues = "='[VBA Chart Creator.xlsm]Sheet1'!$B$1:$D$1"
        End With
        
'3rd year of data
    Set Series2 = ActiveChart.SeriesCollection.NewSeries
        With Series2
            .Name = "Year3"
            'Sets Vertical Axis/Data
            .Values = "='[VBA Chart Creator.xlsm]Sheet1'!H2:J2"
            'sets Horizontal Axis Label
            .XValues = "='[VBA Chart Creator.xlsm]Sheet1'!$B$1:$D$1"
        End With
        
'Names worksheet same as Item #/Chart Title
ActiveSheet.Name = Workbooks("VBA Chart Creator.xlsm").Sheets("Sheet1").Range("A2").Value


'Set Page size as Legal with 1/2 inch margins
With ActiveChart.PageSetup
    .PaperSize = xlPaperLegal
    .RightFooter = "&8Printed " & Format(DateTime.Now, "MM/DD/YYYY")
    .LeftMargin = Application.InchesToPoints(0.5)
    .RightMargin = Application.InchesToPoints(0.5)
    .TopMargin = Application.InchesToPoints(0.5)
    .BottomMargin = Application.InchesToPoints(0.5)
    .HeaderMargin = Application.InchesToPoints(0.3)
    .FooterMargin = Application.InchesToPoints(0.3)
End With


'Export Chart as PDF
Chart.ExportAsFixedFormat Type:=xlTypePDF
        
End Sub

OS: Mac OS Sierra 10.12.6
Version:
Excel for Mac ver 16.15

Any help would be immensely appreciated! Thank you :)
[FONT=&quot]Save[/FONT][FONT=&quot]Save[/FONT]
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top