Apply condition to range

looping

New Member
Joined
Jun 10, 2011
Messages
18
Hello,

I have two ranges containing data to plot in a chart:
Code:
With ActiveChart.SeriesCollection.NewSeries
    .XValues = rngXData
    .Values = rngYData
End With
Now, I want to display only those data values, who match two conditions: " > LowerThres" and "<intupperthres".
<intupperthres".
<intupperthres".
<intupperthres".
< UpperThres".

I already experimented with find and Autofilter but I did not got it to work.</intupperthres".
</intupperthres".
</intupperthres".
</intupperthres".
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I found a solution: I define two new ranges with are set up by the parts of rngXData and rngYData that meet the specifications:

Code:
Private Sub redrawChart(strChartName As String, rngXData As Range, rngYData As Range)
    Dim i As Integer
    Dim j As Integer
    Dim rngXSel As Range
    Dim rngYSel As Range
    ' delete old data
    ActiveSheet.ChartObjects(strChartName).Activate
    For i = ActiveChart.SeriesCollection.Count To 1 Step -1
        ActiveChart.SeriesCollection(i).Delete
    Next
    ' write new data
    For i = 1 To lbxGrenzen.ListCount - 1
        ' rngXSel und rngYSel store the subranges that contain points in the actual interval
        Set rngXSel = Nothing
        Set rngYSel = Nothing
        For j = 1 To rngXData.rows.Count
            If rngXData(j, 1) >= CDbl(lbxGrenzen.List(i - 1)) And rngXData(j, 1) <= CDbl(lbxGrenzen.List(i)) Then
                If rngXSel Is Nothing Then
                    Set rngXSel = rngXData(j, 1)
                Else
                    Set rngXSel = Union(rngXSel, rngXData(j, 1))
                End If
                If rngYSel Is Nothing Then
                    Set rngYSel = rngYData(j, 1)
                Else
                    Set rngYSel = Union(rngYSel, rngYData(j, 1))
                End If
            End If
        Next
        With ActiveChart.SeriesCollection.NewSeries
            .XValues = rngXSel
            .Values = rngYSel
        End With
    Next
End Sub
It might not be the most elegant solution, but it works :smile:

PS: Where is the button to close a thread respectively change it's status to "answer"?
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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