VBA Chart formatting

Newlivez

New Member
Joined
Aug 19, 2014
Messages
13
Hi ladies & gentlemen,

I have a VBA code that generates a graph with 21 different series from one dataset, with as purpose to be able to show a series names as datalabel for every datapoint. In this way I can use "3 Dimensions" in one scatterplot.

Everything is working fine, except that I want to show the right datalabels automatically. In the code I have now this only works for the last datapoint, the rest shows normal datalabels with only numbers instead of the series name. Perhaps someone can suggest how to adapt the code so the Loop executes the right way.

I have highlighted the part of the code in bold that is not executing corretly. Any pointers for me?

Rich (BB code):
Sub LabelPoints2()'
'
    ActiveSheet.ChartObjects("CompetenceMap").Activate
    ActiveChart.ChartArea.Select
    
    Dim myXValues As Range
    Dim myYValues As Range
    Dim myNameValues As Range
    
    Set myXValues = Application.InputBox(prompt:="Range of X Values?", Type:=8)
    Set myYValues = Application.InputBox(prompt:="Range of Y Values?", Type:=8)
    Set myNameValues = Application.InputBox(prompt:="Range of Labels?", Type:=8)
      
    For i = 1 To 21
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(i).XValues = myXValues(i)
    ActiveChart.SeriesCollection(i).Values = myYValues(i)
    ActiveChart.SeriesCollection(i).Name = myNameValues(i)
    
        ActiveChart.SeriesCollection(i).Select
    With Selection.Border
        .Weight = xlHairline
        .LineStyle = xlNone
    End With
    With Selection
        .MarkerBackgroundColorIndex = 25
        .MarkerForegroundColorIndex = 25
        .MarkerStyle = xlDiamond
        .Smooth = False
        .MarkerSize = 5
        .Shadow = False
    End With
    ActiveChart.SetElement (msoElementDataLabelRight)
    ActiveChart.ApplyDataLabels
    ActiveChart.SeriesCollection(i).DataLabels.Select
    Selection.ShowSeriesName = True
    Selection.ShowValue = False
    Next
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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