+ Reply to Thread
Results 1 to 2 of 2

Ignore plotting a series if all y-values are NA()

Hybrid View

  1. #1
    Registered User
    Join Date
    04-27-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003
    Posts
    16

    Ignore plotting a series if all y-values are NA()

    Hi,

    I have a conditional charting code set up such that if a certain value is greater than some threshold, only that value will be plotted with a larger marker. For example, I'm looking at the peak pressure provided from a test. If the value of the pressure is greater than 20 (but less than 40) in the data set, I will plot that specific value with a marker that is a different shape (say diamond), size (10), and color (say gray). If pressure is normal, the markers will be square,5,pink.

    The code I use is fairly simple:
    ActiveCell.FormulaR1C1 = "=if(and(rc[-1]>20,rc[-1]<40),rc[-2],NA())"
    so a #NA is placed into the P20 column if pressure does NOT exceed the value of 20.

    My problem is that there may be a data set where none of the pressures are greater than 20 which leads to an error. Is there a way to avoid this. Here is my code for plotting the P20 data set on top of the other data set (using the same xValues):

        
    Sheets("PreTraining").Select
            Cells.Find(What:=ln, After:=ActiveCell, LookIn:=xlFormulas, _
                LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                MatchCase:=False, SearchFormat:=False).Activate
        ActiveCell.Select
        ActiveCell.Offset(2, 2).Select
        xr1 = ActiveCell.Row
        xc1 = ActiveCell.Column
        x1 = "r" & xr1 & "c" & xc1
        Selection.End(xlDown).Select
        xr2 = ActiveCell.Row
        xc2 = ActiveCell.Column
        x2 = "r" & xr2 & "c" & xc2
        ActiveCell.Offset(0, 1).Select
        yr2 = ActiveCell.Row
        yc2 = ActiveCell.Column
        y2 = "r" & yr2 & "c" & yc2
        Selection.End(xlUp).Select
        yr1 = ActiveCell.Row
        yc1 = ActiveCell.Column
        y1 = "r" & yr1 & "c" & yc1
        ActiveCell.Offset(0, 2).Select
        yr120 = ActiveCell.Row
        yc120 = ActiveCell.Column
        y120 = "r" & yr120 & "c" & yc120
        Selection.End(xlDown).Select
        yr220 = ActiveCell.Row
        yc220 = ActiveCell.Column
        y220 = "r" & yr220 & "c" & yc220
        ActiveCell.Offset(0, 1).Select
        yr240 = ActiveCell.Row
        yc240 = ActiveCell.Column
        y240 = "r" & yr240 & "c" & yc240
        Selection.End(xlUp).Select
        yr140 = ActiveCell.Row
        yc140 = ActiveCell.Column
        y140 = "r" & yr140 & "c" & yc140
    
        Sheets("Graphical Results").Select
            With ActiveChart.SeriesCollection.NewSeries
                .Name = ln
                .Values = "=" & pr & y1 & ":" & y2
                .XValues = "=" & pr & x1 & ":" & x2
            End With
        ActiveChart.SeriesCollection(5).Select
            With Selection.Border
                .Weight = xlThin
                .LineStyle = xlNone
            End With
            With Selection
                .MarkerBackgroundColorIndex = 38
                .MarkerForegroundColorIndex = 38
                .MarkerStyle = MyMarkers(1)
                .Smooth = True
                .MarkerSize = 5
                .Shadow = False
            End With
        Sheets("Graphical Results").Select
            With ActiveChart.SeriesCollection.NewSeries
                .Name = "P20"
                .Values = "=" & pr & y120 & ":" & y220
                .XValues = "=" & pr & x1 & ":" & x2
            End With
        ActiveChart.SeriesCollection(6).Select
            With Selection.Border
                .Weight = xlThin
                .LineStyle = xlNone
            End With
            With Selection
                .MarkerBackgroundColorIndex = 16
                .MarkerForegroundColorIndex = 16
                .MarkerStyle = MyMarkers(3)
                .Smooth = True
                .MarkerSize = 10
                .Shadow = False
            End With
    I guess the basic solution would be to run a loop of the data where the pressure greater than 20 is populated and if there is no value (or only #NA), then I write an if/then statement around the additional charting series code above?

    Hope this isn't too confusing. Please let me know if more information is necessary.

    Best,

    Mike
    Last edited by michaelbails; 05-25-2010 at 10:16 PM.

  2. #2
    Forum Contributor
    Join Date
    08-11-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    149

    Re: Ignore plotting a series if all y-values are NA()

    I see a few choices which could be combined with an if statement to bypass the chart related code. COUNTIF() being the easiest I can think of. COUNTIF({range for P20 data},"<>NA") would be equal to zero if all values were NA.
    Alternatively you could have a variable in your code that gets flipped on if the data is not NA. So at the end of the data loop, you'd check if it was flipped and then chart as appropriate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1