Pergunta

I have a set of graphs that I generate automatically, that I need to adjust slightly. My Y Axis goes from 0 - 1000 but I have some values outside of this range. For those values that occur beyond 1000 I would like to plot a point at 1000 to alert the user to the fact that the data exists.

A desired features: if it would be at all possible to change the format of an individual data point based on a cell value (ie a cell value greater than 1000) that would be fantastic; this isn't necessary but it would make reviewing the data (nearly 100 charts) even easier.

thanks!

Foi útil?

Solução

If you're using macros to build your charts, do you mind using the macros to add additional columns to your data first? You could add two additional columns, the first to have this simple code to adjust some of your data:

ActiveCell.FormulaR1C1 = "= IF(RC[-1]>999, 1000,RC[-1])"
....then fill down

Then the next column to have a simple count of data points (used later to find the point you're modifying):

Dim i as integer
Dim rng As Range

Set rng = Range("Your Range")
For Each Cell In rng
i = i + 1
cell.value = i
Next

Now plot your graph as you would with the macro, except now you're using the Adjusted Values column. And add this formatting macro:

Dim rng As Range
Dim Point As String

Set rng = Range("c2:c9")
For Each Cell In rng

If Cell.Value > 999 Then
Point = Cell.Offset(0, 1).Value

ActiveSheet.ChartObjects("Your Chart").Activate
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Points(Point).Select
Selection.MarkerStyle = -4105
    With Selection
    .MarkerStyle = 2
    .MarkerSize = 25
    .MarkerColor = 'Your Color (could base this off of the degree that it is above 1k)
    End With
End If
Next

This is strong-arming the system a bit, but it would give you what you needed.

Good luck.

-ZL

Outras dicas

You can achieve this effect on a scatter chart by adding a new data series that has the value of 1000 where the existing series exceeds 1000 and has blanks elsewhere. This has to be done for each axis that has values that exceed the maximum you have set.


For example, here is a small data set and the additional data series that would be needed if the maximum Y value on the scatter chart was set to 10.

data with new series


When you add the new Y series to the chart, you will need to specify both the added Series Y range and the original Series X range. Provide a descriptive series name if you want the legend to indicate what the new data points mean,

adding the new series to the chart


Here's a (slightly) cleaned-up version of the chart with the Y-axis maximum set and a legend entry for the new data point. If the points that were exceeding the maximum were on the X-axis, you would go through a similar process.

the new chart

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top