Results 1 to 3 of 3

Thread: Do/While Loop for Range for Plotting portion of Data

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    3

    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

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    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?

  3. #3
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    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!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Posting Permissions

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



Click Here to Expand Forum to Full Width