I am running Excel 2003 and I have several charts on one worksheet where the source data comes from named ranges. I have a scroll bar in place for these charts for users to "scroll" through the data as more is added. The problem I have is we want data labels but only on the data points that are more than or less than a specific value. I had an idea that if I created a "hidden" data range where the data is based on an IF statement that would do the trick, but the data labels for the "blank" cells in the data still come into the chart. The labels are the category name not the value. We need to highlight the category name as this indicates a data point of concern if it is above or below a specific value. I need the data label to move with the data point as the scroll bar is advanced.
I went search for some VB code that might do this programmatically and found this:
Private Sub DataLabels()
' Declare all variable
Dim iPts As Integer
Dim nPts As Integer
Dim aVals As Variant
Dim srs As Series
For Each srs In Charts(1).SeriesCollection
With srs
If Not .HasDataLabels Then
.HasDataLabels = True
End If
nPts = .Points.Count
aVals = .Values
For iPts = 1 To nPts
If aVals(iPts) = 0 Then
' If the value is blank or 0, then hide the chart labels
.Points(iPts).HasDataLabel = False
Else
' If there is something great than 0, show all the stuff on the chart
.Points(iPts).ApplyDataLabels xlDataLabelsShowLabelAndPercent, True, False, True, False, True, True, True, True
End If
Next
End With
Next
End Sub
and thought I could adapt it to my 'hidden' data field, but by VB knowledge in Excel is limited. Can anyone point
me in the right direction as I have 36 charts to work with. Thank you.
I went search for some VB code that might do this programmatically and found this:
Private Sub DataLabels()
' Declare all variable
Dim iPts As Integer
Dim nPts As Integer
Dim aVals As Variant
Dim srs As Series
For Each srs In Charts(1).SeriesCollection
With srs
If Not .HasDataLabels Then
.HasDataLabels = True
End If
nPts = .Points.Count
aVals = .Values
For iPts = 1 To nPts
If aVals(iPts) = 0 Then
' If the value is blank or 0, then hide the chart labels
.Points(iPts).HasDataLabel = False
Else
' If there is something great than 0, show all the stuff on the chart
.Points(iPts).ApplyDataLabels xlDataLabelsShowLabelAndPercent, True, False, True, False, True, True, True, True
End If
Next
End With
Next
End Sub
and thought I could adapt it to my 'hidden' data field, but by VB knowledge in Excel is limited. Can anyone point
me in the right direction as I have 36 charts to work with. Thank you.