Do/While Loop for Range for Plotting portion of Data
I have thousands of lines of data and I need to select portion of this data and plot it. Data is being chosen based on values passed onto some cells in the sheet. See code below. The challenge is that I dont know how to use DO/While loop to do it for different cell values...
In the code below B1766 cell takes values from 1 through 5 and C1766 takes values from 1 through 11 and as you can see D1766 takes values from 1 through 7. Can anyone please help figure this out?
If Worksheets("Sheet7").Range("B1766").Value = 1 Then
If Worksheets("Sheet7").Range("C1766").Value = 1 Then
If Worksheets("Sheet7").Range("D1766").Value = 1 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D334:Q337")
End If
If Worksheets("Sheet7").Range("D1766").Value = 2 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D338:Q341")
End If
If Worksheets("Sheet7").Range("D1766").Value = 3 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D342:Q345")
End If
If Worksheets("Sheet7").Range("D1766").Value = 4 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D346:Q349")
End If
If Worksheets("Sheet7").Range("D1766").Value = 5 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D350:Q353")
End If
If Worksheets("Sheet7").Range("D1766").Value = 6 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D354:Q355")
End If
If Worksheets("Sheet7").Range("D1766").Value = 7 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D356:Q359")
End If
End If
If Worksheets("Sheet7").Range("C1766").Value = 2 Then
If Worksheets("Sheet7").Range("D1766").Value = 1 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D360:Q363")
End If
If Worksheets("Sheet7").Range("D1766").Value = 2 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D364:Q367")
End If
If Worksheets("Sheet7").Range("D1766").Value = 3 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D368:Q371")
End If
If Worksheets("Sheet7").Range("D1766").Value = 4 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D372:Q375")
End If
If Worksheets("Sheet7").Range("D1766").Value = 5 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D376:Q379")
End If
If Worksheets("Sheet7").Range("D1766").Value = 6 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D380:Q381")
End If
If Worksheets("Sheet7").Range("D1766").Value = 7 Then
Worksheets("Sheet5").ChartObjects("Chart 6").Activate
ActiveChart.SetSourceData Source:=Sheets("Sheet7").Range("D382:Q385")
End If
End If
Re: Do/While Loop for Range for Plotting portion of Data
It's not real clear what you're trying to do.
How many different combinations of those 3 cells' values do you need to respond to? All possible combinations?
Re: Do/While Loop for Range for Plotting portion of Data
The multiple IFs in code posted could be changed to nested Select Case!
I don't see any point in using a Do Loop in the posted code!