cyrilbrd
09-30-2012, 10:15 PM
The following code add Data Labels:
Sub AddDataLabels1()
Dim seSales As Series
Dim pts As Points
Dim pt As Point
Dim rngLabels As Range
Dim iPointIndex As Integer
Set rngLabels = Range("AB6:BK6")
Set seSales = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
seSales.HasDataLabels = True
Set pts = seSales.Points
For Each pt In pts
iPointIndex = iPointIndex + 1
pt.DataLabel.Text = rngLabels.Cells(iPointIndex).Text
pt.DataLabel.Font.Bold = True
pt.DataLabel.Position = xlLabelPositionAbove
Next pt
End Sub
What should I add to be able to toggle this vba on/off?
Should it be like
Sub AddDataLabels1()
Application.ScreenUpdating = False
Dim seSales As Series
Dim pts As Points
Dim pt As Point
Dim rngLabels As Range
Dim iPointIndex As Integer
Set rngLabels = Range("AB6:BK6")
Set seSales = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
seSales.HasDataLabels = True
Set pts = seSales.Points
For Each pt In pts
iPointIndex = iPointIndex + 1
pt.DataLabel.Text = rngLabels.Cells(iPointIndex).Text
pt.DataLabel.Font.Bold = True
pt.DataLabel.Position = xlLabelPositionAbove
Next pt
Application.ScreenUpdating = True
End Sub
Sub AddDataLabels1()
Dim seSales As Series
Dim pts As Points
Dim pt As Point
Dim rngLabels As Range
Dim iPointIndex As Integer
Set rngLabels = Range("AB6:BK6")
Set seSales = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
seSales.HasDataLabels = True
Set pts = seSales.Points
For Each pt In pts
iPointIndex = iPointIndex + 1
pt.DataLabel.Text = rngLabels.Cells(iPointIndex).Text
pt.DataLabel.Font.Bold = True
pt.DataLabel.Position = xlLabelPositionAbove
Next pt
End Sub
What should I add to be able to toggle this vba on/off?
Should it be like
Sub AddDataLabels1()
Application.ScreenUpdating = False
Dim seSales As Series
Dim pts As Points
Dim pt As Point
Dim rngLabels As Range
Dim iPointIndex As Integer
Set rngLabels = Range("AB6:BK6")
Set seSales = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
seSales.HasDataLabels = True
Set pts = seSales.Points
For Each pt In pts
iPointIndex = iPointIndex + 1
pt.DataLabel.Text = rngLabels.Cells(iPointIndex).Text
pt.DataLabel.Font.Bold = True
pt.DataLabel.Position = xlLabelPositionAbove
Next pt
Application.ScreenUpdating = True
End Sub