Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to format excel chart data labels using vba

Status
Not open for further replies.

bookouri

IS-IT--Management
Feb 23, 2000
1,464
US
Im dont usually use Excel, but Im working on a project where I have to create some charts and configure the chart components using vba. Ive had pretty good luck recording macros and then using the code, but when i record some things like data labels alignment and format and text attributes the macro recorder does not capture those settings. Is there some way to record these settings so I can add them to my code? or point me to a good reference for the chart object? I tried looking for a reference with the settings, but havnt had any luck finding anything useful.

thanks for any help
 



Hi,

are you actually changing those data label properties as you record? You have to actually CHANGE the properties, not just open the dialogs.

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
I don't know if it will help, but here is a quick example of how to address and change the labels on a chosen series.

It assumes you are working with the active chart, you have chosen a particular series and know its number, designated by "n". It also assumes you have created an array of strings ("MyDataLabels()") you want to use as the labels of your chosen series, and that the size of the string array is at least as big as the number of points in the series.

Code:
'To address the series:
Dim selectedseries As Series
set selectedseries = = ActiveChart.SeriesCollection(n)


'To apply labels:
selectedseries.ApplyDataLabels

'To address the labels:
for i = 1 to selectedseries.Points.Count
  selectedseries.Points(i).DataLabel.Text = MyDataLabels(i)
next i

I hope that helps.

Tony

 
thanks ill try that code.. but yes during the macro record i was actually changing the font size and alignment and it appeared on the chart, but in the macro code there was just nothing but the chart select code..
 
Oops - If you do cut'n'paste the code I posted, please note that I got over-enthusiastic with the "=". The line:

set selectedseries = = ActiveChart.SeriesCollection(n)

should read:

set selectedseries = ActiveChart.SeriesCollection(n)

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top