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
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