Format Data in a Chart Data Table

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.enter image description here

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?

4

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

or

Worksheets(1).ChartObjects(1).Chart _ .SeriesCollection(1).DataLabels(5).NumberFormat = "0.000"
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like