vendredi 24 juin 2016

Syntax / Loop Errors


I am coding a nested loop to run through every cell (row and then column) of a table I have. Each cell has a distinct "combination" that it must be equal to, and if it matches values that I am referencing on another sheet, it will take a value (specified in Analysis worksheet) from that same row and return it in this table. Here's my code. I am getting an error in the larger If statement. Any help is appreciated. Thanks!

Sub GraphLoop()

Dim i As Long
Dim j As Long
Dim k As Long
Dim m As Long

Worksheets("Chart Data").Range("C6:DR10000").Value = ""

j = 3

Do Until Worksheets("Chart Data").Cells(4, j).Value = ""

For i = 4 To Rows.Count

k = i + 3

m = i + 2

ThisWorkbook.Sheets("Running Avg Log").Activate

    ' If the current row in running avg log doesnt meet this if statement criteria, it skips & increments i w/o doing anything
    If Sheets("Running Avg Log").Cells(i, 2).Value = 1 _
        And Sheets("Running Avg Log").Cells(i, 3).Value = 1 _
        And Sheets("Running Avg Log").Cells(i, 4).Value = 1 _
        And Sheets("Running Avg Log").Cells(i, 1).Value = Sheets("Chart Data").Cells(k, 1).Value Then

        ThisWorkbook.Sheets("Chart Data").Activate

        ' When if statement is entered, this sets the selected dimension # in this accepted row and puts it into corresponding spot in chart data
        Worksheets("Chart Data").Cells(m, j).Value = Worksheets("Running Avg Log").Cells(i, 6 + Worksheets("Analysis").Range("C5").Value).Value

    End If

Next i

' j (column number) will increment across after each row in one column is done, testing the entire table
j = j + 1
Loop

End Sub

sheet where code will input the values

sheet where the values are found. If statement looks for date, and the three values following the date. If they match what i want, it returns one of the dimension numbers in that same row. The dimension number is a drop down menu cell selected in the Analysis worksheet, and can be referenced with the cell I have shown in the line within the If statement.


Aucun commentaire:

Enregistrer un commentaire