bpjewell
New Member
- Joined
- Mar 9, 2012
- Messages
- 43
I have cobbled together a macro using various bits and pieces of information that I have searched for and almost got the desired result but getting stuck at the final hurdle and wondered if anyone here can help.
What I am trying to do is delete the series names from a chart when the value is zero (which is working) and then format all of the data series so that the text is rotated 90 degrees and font size 8.
The code below is almost there but is only formatting the first data series and I don't know how to get it to change all the data. The chart data is dynamic (it changes on a weekly basis) but all of that is set up to work automatically using other formulas and macros.
I know that there is unnecessary code in the macro below but due to my limited understanding (which is increasing thanks, mostly, to this very helpful forum) I am unable to remove or re-write the bits that I don't need.
If anyone could help me with getting the last section of the code to reformat all the data labels I would be very grateful
What I am trying to do is delete the series names from a chart when the value is zero (which is working) and then format all of the data series so that the text is rotated 90 degrees and font size 8.
The code below is almost there but is only formatting the first data series and I don't know how to get it to change all the data. The chart data is dynamic (it changes on a weekly basis) but all of that is set up to work automatically using other formulas and macros.
I know that there is unnecessary code in the macro below but due to my limited understanding (which is increasing thanks, mostly, to this very helpful forum) I am unable to remove or re-write the bits that I don't need.
If anyone could help me with getting the last section of the code to reformat all the data labels I would be very grateful
Code:
Sub Show_Labels_Greater_Than_Zero()
Dim srs As Series, i As Long, cht As Chart
ActiveSheet.ChartObjects("Chart 9").Activate
On Error Resume Next
Set cht = ActiveChart
On Error GoTo 0
If cht Is Nothing Then
MsgBox "Please select a chart first.", vbInformation, "No Chart Selected"
Else
cht.ApplyDataLabels AutoText:=True, LegendKey:=False, _
HasLeaderLines:=False, ShowSeriesName:=True, ShowCategoryName:=False, _
ShowValue:=False, ShowPercentage:=False, ShowBubbleSize:=False
For Each srs In cht.SeriesCollection
For i = 1 To UBound(srs.Values)
If srs.Values(i) <= 0 Then srs.Points(i).DataLabel.Delete
Next i
Next srs
End If
With ActiveChart
With .SeriesCollection(1)
With .DataLabels
.Font.Size = 8
.VerticalAlignment = xlTop
.Orientation = 90
End With
End With
End With
End Sub