millhouse123
Active Member
- Joined
- Aug 22, 2006
- Messages
- 335
I am trying to automate 2 pie charts on the same Worksheet but I cannot get them to be the same size even though all of the size properties are the same. Any idea why the second pie chart would be much smaller than the first. I have never used VBA with charts so any advice on cleaning up the code would be helpful too.
Thanks
Thanks
Code:
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=WS1.Range("B11").Resize(Rowsize, 2), PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Current VS. Target"
ActiveChart.HasLegend = False
With Selection.Border
.LineStyle = xlNone
End With
Selection.Interior.ColorIndex = xlNone
ActiveChart.ChartArea.Select
With Selection.Border
.LineStyle = xlNone
End With
ActiveChart.PlotArea.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlNone
End With
Selection.Interior.ColorIndex = xlNone
With ActiveSheet.ChartObjects(1)
.Top = 322.5
.Left = 70
.Width = 337.5
.Height = 264
End With
With ActiveChart.PlotArea
.Top = 231.75
.Left = 175
.Width = 400
.Height = 326.5
End With
ActiveChart.SeriesCollection(1).Select
ActiveChart.ChartArea.Select
ActiveChart.ApplyDataLabels AutoText:=True, LegendKey:=False, _
HasLeaderLines:=True, ShowSeriesName:=False, ShowCategoryName:=True, _
ShowValue:=True, ShowPercentage:=True, ShowBubbleSize:=False
With Selection.Font
.Size = 12
End With
Range("I25").Select
'Workbooks("Consolidator.xls").Activate
'Worksheets("Summary_Report").Activate
'WS2.Activate 'must be active so chart is put in right spot.
Charts.Add
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=WS1.Range("B11").Resize(Rowsize, 5), PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Current VS. Target"
ActiveChart.HasLegend = False
With Selection.Border
.LineStyle = xlNone
End With
Selection.Interior.ColorIndex = xlNone
ActiveChart.ChartArea.Select
With Selection.Border
.LineStyle = xlNone
End With
ActiveChart.PlotArea.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlNone
End With
Selection.Interior.ColorIndex = xlNone
With ActiveChart
Do Until .SeriesCollection.Count = 0
.SeriesCollection(1).Delete
Loop
End With
With ActiveChart.SeriesCollection.NewSeries
.Values = WS1.Range("G11").Resize(Rowsize, 1)
.XValues = WS1.Range("B11").Resize(Rowsize, 1)
End With
With ActiveSheet.ChartObjects(2)
.Top = 322.5
.Left = 450
.Width = 337.5
.Height = 264
End With
With ActiveChart.PlotArea
.Top = 231.75
.Left = 175
.Width = 400
.Height = 326.5
End With
ActiveChart.SeriesCollection(1).Select
ActiveChart.ChartArea.Select
ActiveChart.ApplyDataLabels AutoText:=True, LegendKey:=False, _
HasLeaderLines:=True, ShowSeriesName:=False, ShowCategoryName:=True, _
ShowValue:=False, ShowPercentage:=True, ShowBubbleSize:=False
With Selection.Font
.Size = 12
End With