graph point labeling via macro on Mac version of Excel

roscoe

Well-known Member
Joined
Jun 4, 2002
Messages
1,062
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have a financial graph of multiple account values over time. Each column is a quarter, and as each quarter passes over time I add a new column left of the current data. All of the data except the current (rightmost in the table and on the graph) is static whereas the current data is formula-driven. On the graph, most of the past data has data labels using the "default" format (a few have been manually edited to highlight something); the current (rightmost) data uses a custom label.

Here's the issue and the question...When it becomes time to add the new quarterly column, my intent is for the custom labels to stay with the current (rightmost) data and the new column data picks up the default format. Alas, that's proving impossible to do easily. No matter how I do it, the newly added column picks up the custom formatting and the original rightmost data changes to the default formatting. I've tried copying the rightmost column to the right, then replacing the previous column with the required static data, and I've tried inserting a blank column left of the rightmost data and then filling in the gaps. Neither works in terms of the data label formatting; I have to manually fix the labeling for ten data points (the last two points on five different sets of data). I'm tired of doing that. There's has to be a way.

Before anyone says "use a macro" which is of course obvious, I'm doing this on a Mac, and all of my previous macro work (somewhat extensive) has been on a PC...and all that was on a work computer to which I no longer have access.

Any hints (links would be fine) to a macro that will loop through selected data sets (not all of them are current, some old account data is plotted for historical reference), and set the last two points only.

Thanks!

(Standing by to clarify my rather complex question)
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Good to hear you figured out a solution.
If you would like to post the solution then it is perfectly fine to mark that post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0
I thought marking it as answered would close the thread...but OK
 
Upvote 0
I thought marking it as answered would close the thread.
Fair enough, however we generally don't "close" threads in these forums (unless something untoward has happened in the thread) as it is always possible that a better answer might subsequently be posted even after the OP has accepted an answer. Anyway, all good here now. :)
 
Upvote 0
VBA Code:
Sub Update_labels()

ActiveSheet.ChartObjects("Chart 3").Activate

Dim iSrs As Long
Dim iPts As Long
For iSrs = 2 To 6 'ActiveChart.SeriesCollection.Count
    
'2= Green series
'3= Orange series
'4= Purple series
'5= Red series
'6= Maroon series

'Note that series "1" doesn't have labels so no editing required
    
    With ActiveChart.SeriesCollection(iSrs)
        iPts = .Points.Count
        With .Points(iPts) 'This corrects the last label in every series
            .ApplyDataLabels
            .DataLabel.ShowSeriesName = True
            .DataLabel.Position = xlLabelPositionRight
            .DataLabel.Separator = "-"
            .DataLabel.Font.Name = "Calibri"
            .DataLabel.Font.FontStyle = "Bold"
            .DataLabel.Font.Size = 8
           '.DataLabel.NumberFormat = "#,##0.00"
        End With '.Points(iPts)
        
        Select Case iSrs. 'This corrects the second to last label in two of the series
       
        Case 2, 5
            With .Points(iPts - 1)
                .ApplyDataLabels
                .DataLabel.ShowSeriesName = False
                .DataLabel.Position = xlLabelPositionBelow
                .DataLabel.Font.Name = "Calibri"
                .DataLabel.Font.FontStyle = "Normal"
                .DataLabel.Font.Size = 8
               '.DataLabel.NumberFormat = "#,##0.00"
            End With '.Points(iPts - 1)
            
        Case 3, 4, 6 'This removes the second to last label in three other series
            With .Points(iPts - 1)
            If .HasDataLabel = True Then .DataLabel.Delete
            End With '.Points(iPts - 1)
            
        End Select
        
    End With 'ActiveChart.SeriesCollection(iSrs)
Next 'iSrs = 1 To ActiveChart.SeriesCollection.Count

End Sub
 
Upvote 0
Solution
To clarify why I did the select case statement (if it'd not obvious), is 3/5 series do not have labels on any but the last data point so I make sure they go away after the column insert moves the label to that point. The other 2/5 labels have every data point labeled and as such the second to last has to be reset to my "default".
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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