VBA to create a new pie chart for each row of data

tkuly

New Member
Joined
Feb 4, 2014
Messages
1
Hello!
I am very new to VBA and any help would be appreciated. I am trying to create a pie chart for each row of data in my worksheet. So far I have the following code, and it works but the data labels for the legend are missing; the labels I would want included are the the annual salary, pension contribution, and benefits paid. Sample data:

[TABLE="width: 543"]
<tbody>[TR]
[TD]EE #
[/TD]
[TD]First
[/TD]
[TD]Last
[/TD]
[TD]Annual Salary
[/TD]
[TD]Pension Contribution
[/TD]
[TD]Benefits Paid
[/TD]
[/TR]
[TR]
[TD]11
[/TD]
[TD]Jane
[/TD]
[TD]Klemp
[/TD]
[TD]$26,000.00
[/TD]
[TD]$3,389.57
[/TD]
[TD]$5,000.00
[/TD]
[/TR]
[TR]
[TD]22
[/TD]
[TD]Brigette
[/TD]
[TD]Fisgue
[/TD]
[TD]$105,000.00
[/TD]
[TD]$3,458.00
[/TD]
[TD]$5,000.00
[/TD]
[/TR]
[TR]
[TD]33
[/TD]
[TD]Jamal
[/TD]
[TD]Salas
[/TD]
[TD]$42,000.00
[/TD]
[TD]$2,750.38
[/TD]
[TD]$5,000.00
[/TD]
[/TR]
</tbody>[/TABLE]


Can anyone help me out? Thanks in advance

Sub AllCharts()
Dim i As Long
Dim LastRow As Long
Dim LastColumn As Long
Dim chrt As Chart
LastRow = Sheets("Sheet1").Range("A3000").End(xlUp).Row
LastColumn = Sheets("Sheet1").Range("A1").End(xlToRight).Column
For a = 2 To LastRow
Sheets("Sheet2").Select
Set chrt = Sheets("Sheet2").Shapes.AddChart.Chart
chrt.ChartType = xlPieExploded
With Sheets("Sheet1")
chrt.SetSourceData Source:=.Range(.Cells(a, 2), .Cells(a, LastColumn))
End With

chrt.ChartArea.Left = 1
chrt.ChartArea.Top = (a - 2) * chrt.ChartArea.Height
Next

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,226,730
Messages
6,192,702
Members
453,748
Latest member
akhtarf3

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