ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Charts and Charting in Excel (https://www.excelbanter.com/charts-charting-excel/)
-   -   chart label macro (https://www.excelbanter.com/charts-charting-excel/129197-chart-label-macro.html)

Gklass

chart label macro
 
Here's macro for labelling XY charts.

but it only works for the the first series (you can reorder the
series)
and the labels have to be in the column (the data have to be in
colums), to the left of the X-axis.

but it works in 007

http://support.microsoft.com/kb/213750

Sub AttachLabelsToPoints()

'Dimension variables.
Dim Counter As Integer, ChartName As String, xVals As String

' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False

'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula

'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop

'Attach a label to each data point in the chart.
For Counter = 1 To Range(xVals).Cells.Count
ActiveChart.SeriesCollection(1).Points(Counter).Ha sDataLabel = _
True
ActiveChart.SeriesCollection(1).Points(Counter).Da taLabel.Text =
_
Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
Next Counter

End Sub


Jon Peltier

chart label macro
 
Ever try one of these?

Rob Bovey's Chart Labeler, http://appspro.com
John Walkenbach's Chart Tools, http://j-walk.com

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Gklass" wrote in message
oups.com...
Here's macro for labelling XY charts.

but it only works for the the first series (you can reorder the
series)
and the labels have to be in the column (the data have to be in
colums), to the left of the X-axis.

but it works in 007

http://support.microsoft.com/kb/213750

Sub AttachLabelsToPoints()

'Dimension variables.
Dim Counter As Integer, ChartName As String, xVals As String

' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False

'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula

'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop

'Attach a label to each data point in the chart.
For Counter = 1 To Range(xVals).Cells.Count
ActiveChart.SeriesCollection(1).Points(Counter).Ha sDataLabel = _
True
ActiveChart.SeriesCollection(1).Points(Counter).Da taLabel.Text =
_
Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
Next Counter

End Sub




Gklass

chart label macro
 
JOn:
Bovey's won't run in 007
Walkenb's might run but it doesn't appear on any menu.



On Feb 4, 5:28 pm, "Jon Peltier"
wrote:
Ever try one of these?

Rob Bovey's Chart Labeler,http://appspro.com
John Walkenbach's Chart Tools,http://j-walk.com

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutionshttp://PeltierTech.com
_______

"Gklass" wrote in message

oups.com...

Here's macro for labelling XY charts.


but it only works for the the first series (you can reorder the
series)
and the labels have to be in the column (the data have to be in
colums), to the left of the X-axis.


but it works in 007


http://support.microsoft.com/kb/213750


Sub AttachLabelsToPoints()


'Dimension variables.
Dim Counter As Integer, ChartName As String, xVals As String


' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False


'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula


'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop


'Attach a label to each data point in the chart.
For Counter = 1 To Range(xVals).Cells.Count
ActiveChart.SeriesCollection(1).Points(Counter).Ha sDataLabel = _
True
ActiveChart.SeriesCollection(1).Points(Counter).Da taLabel.Text =
_
Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
Next Counter


End Sub




Gklass

chart label macro
 
OK I found it!!!
on the add ins thing

On Feb 4, 5:28 pm, "Jon Peltier"
wrote:
Ever try one of these?

Rob Bovey's Chart Labeler,http://appspro.com
John Walkenbach's Chart Tools,http://j-walk.com

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutionshttp://PeltierTech.com
_______

"Gklass" wrote in message

oups.com...

Here's macro for labelling XY charts.


but it only works for the the first series (you can reorder the
series)
and the labels have to be in the column (the data have to be in
colums), to the left of the X-axis.


but it works in 007


http://support.microsoft.com/kb/213750


Sub AttachLabelsToPoints()


'Dimension variables.
Dim Counter As Integer, ChartName As String, xVals As String


' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False


'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula


'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop


'Attach a label to each data point in the chart.
For Counter = 1 To Range(xVals).Cells.Count
ActiveChart.SeriesCollection(1).Points(Counter).Ha sDataLabel = _
True
ActiveChart.SeriesCollection(1).Points(Counter).Da taLabel.Text =
_
Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
Next Counter


End Sub




Jon Peltier

chart label macro
 
To extend this to any series, use the appropriate index wherever this
occurs:

SeriesCollection(1)

or change the reference point so that you select a series and run a macro,
and change

ActiveChart.SeriesCollection(1)

to

Selection

Put this up front to bail out if no series is selected:

If TypeName(Selection) < "Series" Then Exit Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Gklass" wrote in message
oups.com...
Here's macro for labelling XY charts.

but it only works for the the first series (you can reorder the
series)
and the labels have to be in the column (the data have to be in
colums), to the left of the X-axis.

but it works in 007

http://support.microsoft.com/kb/213750

Sub AttachLabelsToPoints()

'Dimension variables.
Dim Counter As Integer, ChartName As String, xVals As String

' Disable screen updating while the subroutine is run.
Application.ScreenUpdating = False

'Store the formula for the first series in "xVals".
xVals = ActiveChart.SeriesCollection(1).Formula

'Extract the range for the data from xVals.
xVals = Mid(xVals, InStr(InStr(xVals, ","), xVals, _
Mid(Left(xVals, InStr(xVals, "!") - 1), 9)))
xVals = Left(xVals, InStr(InStr(xVals, "!"), xVals, ",") - 1)
Do While Left(xVals, 1) = ","
xVals = Mid(xVals, 2)
Loop

'Attach a label to each data point in the chart.
For Counter = 1 To Range(xVals).Cells.Count
ActiveChart.SeriesCollection(1).Points(Counter).Ha sDataLabel = _
True
ActiveChart.SeriesCollection(1).Points(Counter).Da taLabel.Text =
_
Range(xVals).Cells(Counter, 1).Offset(0, -1).Value
Next Counter

End Sub





All times are GMT +1. The time now is 06:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com