Formatting Data Series Using Macro

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 :)

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
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,215,417
Messages
6,124,783
Members
449,188
Latest member
Hoffk036

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top