I'm working on a project where I'm creating charts programmatically using VBA. These charts include data tables. The business requirements specify that the chart data cannot be tied to the source data, so the data is embedding in the chart itself.
I'm struggling to see how to format the numbers in the table to have two decimal places...In the example above the 0.1 needs to be 0.10 and the 1 needs to be 1.00. The chart removes any trailing zeros I add to the source data, and I see no options to format the data table number format. I don't know if there's a VBA answer to this or if I could find it by recording a macro, but I can't even figure it out manually! Any thoughts?
41 Answer
You should be able to do this using the DataLabel object.
Examples from the linked MSDN:
With Charts(1).SeriesCollection(1) .HasDataLabels = True .DataLabels.NumberFormat = "##.##"
End Withor
Worksheets(1).ChartObjects(1).Chart _ .SeriesCollection(1).DataLabels(5).NumberFormat = "0.000" 2