Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50190

XY Scatter Chart: unique point colors and shapes

$
0
0
I am having difficulty assigning unique point colors/shapes in a X Y scatter plot based on corresponding color and shape ID numbers contained in two columns of my data table.

To provide some background, I have created a dynamic XY scatter chart that is controlled via a userform that allows the user to plot by categories or individual data elements. This chart is based off a table that contains the data- organized by category columns, X/Y values and labels. There are also two columns in this table which contain unique ID numbers according to the Category column (Cat.1 = ID# 1, Cat.2 = ID# 2, etc.)

When the user uses the form to plot by a selected category, the data table is updated to show only those rows where the data matches that category and the chart is updated to plot the data for that category. The user can also choose to plot by directly selecting any individual data elements (regardless of category) and the data table will show only those selected- updating the chart as well.

I have been able to assign the corresponding data labels to the plotted points, however I cannot figure out how to assign shape/color. My code is show below:
Code:

  'Add Labels/Color, Shape pending
        Dim DataSeries As Series
        Dim SingleCell As Range
        Dim ColorCell As Range
        Dim List As Range
        Dim List2 As Range
        Dim Counter As Integer
       
        Counter = 1
        Set List = Worksheets("Database").Range("IM8", "IM507")
        Set List2 = Worksheets("Database").Range("IN8", "IN507")
       
        Set DataSeries = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
        DataSeries.HasDataLabels = True
        DataSeries.DataLabels.Font.Size = 9
       
        'Add Label
        For Each SingleCell In List
            DataSeries.Points(Counter).DataLabel.Text = SingleCell.Value
            Counter = Counter + 1
        Next SingleCell
       
        'Add Color, this code does not change the points colors as desired
        For Each ColorCell In List2
            DataSeries.Points(Counter).MarkerBackgroundColorIndex = ColorCell.Value
            DataSeries.Points(Counter).MarkerForegroundColorIndex = ColorCell.Value
            Counter = Counter + 1
        Next ColorCell

Any help is greatly appreciated, I hope my problem makes sense.

Viewing all articles
Browse latest Browse all 50190

Trending Articles