Minor Addition to VBA For A Chart

3LeggedDog

Board Regular
Joined
Feb 11, 2006
Messages
149
Hi,
I have some VBA code (from using the Macro Recorder) that does exactly what I'd like it to. The macro looks at a particular range and generates a pie chart, and then removes the chart title. The only issue that I have with it is that the data labels in the pie chart show do not show any decimal values. Is there a quick way to modify this VBA to allow it to set the data labels to show one decimal place? For example, 39.2%, rather than 39%. The VBA is shown below -

Sub Macro13()
'
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlPie
ActiveChart.ApplyLayout (1)
ActiveChart.SetSourceData Source:=Range("A1:B5")
ActiveChart.ChartTitle.Select
Selection.Delete
End Sub


Once that process is completed, I'd also like to run the following macro - which is complete and correct - to force the wedges to be particular colors. All I'm really looking to do here is to stitch the two together. (And credit for this macro goes to Jon Peltier, at http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=390 )

Sub ColorWedges()
Dim iPoint As Long, nPoint As Long
With ActiveChart.SeriesCollection(1)
For iPoint = 1 To .Points.Count
Select Case WorksheetFunction.Index(.XValues, iPoint)
Case "Customer Service"
.Points(iPoint).Interior.ColorIndex = 3 ' Red
Case "Dept Maintenance"
.Points(iPoint).Interior.ColorIndex = 4 ' Green
Case "Safety"
.Points(iPoint).Interior.ColorIndex = 5 ' Blue
Case "Reports"
.Points(iPoint).Interior.ColorIndex = 6 ' Yellow
Case "EEEE"
.Points(iPoint).Interior.ColorIndex = 7 ' Magenta
Case "FFFF"
.Points(iPoint).Interior.ColorIndex = 8 ' Cyan
Case "GGGG"
.Points(iPoint).Interior.ColorIndex = 9 ' Maroon
Case "HHHH"
.Points(iPoint).Interior.ColorIndex = 10 'Dark Green
Case "IIII"
.Points(iPoint).Interior.ColorIndex = 11 'Royal Blue
Case "JJJJ"
.Points(iPoint).Interior.ColorIndex = 12 'Vomit
Case "KKKK"
.Points(iPoint).Interior.ColorIndex = 13 'Bright Purple
Case "LLLL"
.Points(iPoint).Interior.ColorIndex = 14 'Sea Blue

End Select
Next
End With
End Sub

Thanks, as always,
3LD
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,216,404
Messages
6,130,376
Members
449,578
Latest member
TT123

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