Leading the way in Microsoft Office Development
 Home|Excel|Word|PowerPoint|Consultancy|Feedback|Contact 
 Microsoft Excel > Charts Common Problems > Adding Data Labels< Previous | Next > 


 

adding data labels to a scatter or bubble chart.

 
 

If you have a Pie Chart and the data labels are not wide enough to display all the data on one line then a possible work around is to make the chart area a lot bigger but to keep the Plot Area the same size.

 

 
1
2
3
4
5
6
7
8
9
10
Public Sub Chart_AddLabels()
Dim schartname As String
   schartname = Right(ActiveChart.Name, Len(ActiveChart.Name) - Len(ActiveSheet.Name) - 1)
   Set rgerange = Application.InputBox("Select the labels to add", Type:=8)
   snewlabel = rgerange.Address
   ActiveSheet.ChartObjects(schartname).Activate
   Call Chart_DataLabelsAdd(1, rgerange.Column, _
                               rgerange.Row, _
                               rgerange.Row + rgerange.Rows.Count - 1)
End Sub
   

 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Public Sub Chart_DataLabelsAdd(iSeriesNo As Integer, _
                               iColFirst As Integer, _
                               lRowFirst As Long, _
                               lRowLast As Long)
Dim rgerange As Range
Dim lcount As Long
Dim snewlabel As String
Dim lsmallest As Long
   ActiveChart.SeriesCollection(iSeriesNo).ApplyDataLabels Type:=xlDataLabelsShowLabel
   If ActiveChart.SeriesCollection(iSeriesNo).DataLabels.Count <= (lRowLast - lRowFirst + 1) Then
      lsmallest = ActiveChart.SeriesCollection(1).DataLabels.Count
   End If
   If (lRowLast - lRowFirst) <= ActiveChart.SeriesCollection(1).DataLabels.Count Then
      lsmallest = lRowLast - lRowFirst + 1
   End If
   For lcount = 1 To lsmallest
      snewlabel = ActiveSheet.Cells(lRowFirst + lcount - 1, iColFirst).Value
      ActiveChart.SeriesCollection(iSeriesNo).DataLabels.Select
      ActiveChart.SeriesCollection(iSeriesNo).Points(lcount).DataLabel.Select
      Selection.Characters.Text = snewlabel
   Next lcount
End Sub
   


 Copyright © 2004-2007 Better Solutions Limited. All Rights Reserved.< Previous | Top | Next >