cellMatrix.net
Spreadsheet Modeling and Related Topics

About

Formulas, Charts, and Models Created with Microsoft Excel.
More . . .

Statistics

  • Total Entries - 102
  • Current Viewers - 15

Categories

Recent Comments

Syndicate

Validate

XY Scatter Chart - Flag Duplicates

A post sometime ago to the Microsoft Excel Charting Discussion Group asks . . . how can I automatically flag duplicate values on an XY scatter chart with a different colored point? My thought was to write a procedure that identified the duplicates via a helper column in the worksheet, accessed the chart, and then recolored the duplicate points. Assuming an XY scatter chart based on the values in the first and second columns, I added a third helper column. The helper column concatenates the X and Y values.

image

I renamed the chart "Cht1". Assuming a single X and Y series, the code below flags the duplicates. In the example, the marker size for each duplicated point is increased to 10 and the color of the marker is switched from blue to green.

Sub FlayXYDups()

    On Error Resume Next
    Dim Rng As Range
    Dim Cell As Range
    Dim Cnt As Integer
    Dim UniqueValues As New Collection
    Dim ErrColor As Integer
    Dim Cht As ChartObject

    Set Cht = ActiveSheet.ChartObjects("Cht1")

    ErrColor = 10

    Cnt = 0

    For Each Rng In Range("D3:D20")
        Cnt = Cnt + 1
        UniqueValues.Add Rng.Value, CStr(Rng.Value)
        If Err.Number = 457 Then
            With Cht.Chart.SeriesCollection(1).Points(Cnt)
                .MarkerSize = 10
                .MarkerForegroundColorIndex = ErrColor
                .MarkerBackgroundColorIndex = ErrColor
            End With
        Rng.Interior.ColorIndex = ErrColor
        End If
        Err.Number = 0
    Next Rng

End Sub

The chart showing duplicated values looks like this:

image

The procedure also flags the duplicates on the spreadsheet.

image


Okay, extend this a bit farther:

Different marker size based on number of duplicates, with a data label beside the point indicating this number. I have an underdeveloped technique in mind, which may but doesn’t have to involve VBA.

Posted by Jon Peltier  on  08/05  at  07:12 AM

I’m thinking that using two helper columns and two series (one for the duplicates and one for the single values) would be a simple alternative to using VBA.  I’ll put something together soon a post it as a follow-up.

Posted by John Mansfield  on  08/09  at  03:56 AM

The series that plots duplicates could have data labels that indicate how many duplicates there were. A simple countif, perhaps, to count them.

Posted by Jon Peltier  on  08/09  at  06:43 AM


Comment Form

Name: (Required)
E-Mail Address: (Optional)
Location: (Optional)
Web Site Address: (Optional)

Remember my personal information?
Notify me of follow-up comments?

Before submitting your comment, please enter the phrase you see below: