I have a problem that doesn't require difficult, but requires a whole lot of if statements and one while/for loop. I am having trouble getting it to run at all, which leads me to believe the if/end if and do while/loop are oriented incorrectly. There is a crap ton of code here, but I'm not asking to fix the actual code inside each if statement. I just would greatly appreciate some editing on how the whole sub is set up so I know whether I made an error when designing the if statement/while loop combo. Here is the code:
Like I said, I know this is a ton of code, but it's actually not all that bad. There are three major if statements. One of them is at the very beginning of the sub:
The second is almost immediately after it:
which is supposed to have two elseif statements and an else. I think this is written correctly, but I could have missed something.
The third if statement:
is inside the second if, and is repeated in both of the elseifs and the else, just with a different value in the cell reference.
I'm sure this is asking a lot to sift through this, but I've been working on this for almost a full week and still haven't gotten it to work. I'm all tapped out of ideas, and would appreciate a new set of eyes to look over it sooo much.
FYI, when I run the code as is it simply does absolutely nothing to the sheet.
Thanks for the looks everyone. Igreatly appreciate the help.
Hank
Code:
Public Sub Thumbs()
Dim r As Long
r = 10
If Sheets("Optics Report").Range("J" & (r - 1)).Value <> "" Then
Do While (r < 249)
If Sheets("Optics Report").Range("Q" & (r + 5)).Value <> "" Then
If Sheets("Optics Report").Range("T" & (r + 6)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Sheets("Optics Report").Range("T" & (r + 6)).Value - Sheets("Optics Report").Range("M" & (r + 6)).Value)
If Sheets("Optics Report").Range("T" & (r + 6)).Value <= Sheets("Optics Report").Range("M" & (r + 6)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("T" & (r + 5)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("M" & (r + 6)).Value)
If Int(Now) <= Sheets("Optics Report").Range("M" & (r + 6)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("S" & (r + 6)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("M" & (r + 5)).Value)
If Int(Now) <= Sheets("Optics Report").Range("M" & (r + 5)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("S" & (r + 5)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("L" & (r + 6)).Value)
If Int(Now) <= Sheets("Optics Report").Range("L" & (r + 6)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("R" & (r + 6)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("L" & (r + 5)).Value)
If Int(Now) <= Sheets("Optics Report").Range("L" & (r + 5)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("R" & (r + 5)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("K" & (r + 6)).Value)
If Int(Now) <= Sheets("Optics Report").Range("K" & (r + 6)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("Q" & (r + 6)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("K" & (r + 5)).Value)
If Int(Now) <= Sheets("Optics Report").Range("K" & (r + 5)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("Q" & (r + 5)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("J" & (r + 6)).Value)
If Int(Now) <= Sheets("Optics Report").Range("J" & (r + 6)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
Else
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("J" & (r + 5)).Value)
If Int(Now) <= Sheets("Optics Report").Range("J" & (r + 5)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
End If
ElseIf Sheets("Optics Report").Range("Q" & (r + 3)).Value <> "" Then
If Sheets("Optics Report").Range("T" & (r + 4)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Sheets("Optics Report").Range("T" & (r + 4)).Value - Sheets("Optics Report").Range("M" & (r + 4)).Value)
If Sheets("Optics Report").Range("T" & (r + 4)).Value <= Sheets("Optics Report").Range("M" & (r + 4)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("T" & (r + 3)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("M" & (r + 4)).Value)
If Int(Now) <= Sheets("Optics Report").Range("M" & (r + 4)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("S" & (r + 4)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("M" & (r + 3)).Value)
If Int(Now) <= Sheets("Optics Report").Range("M" & (r + 3)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("S" & (r + 3)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("L" & (r + 4)).Value)
If Int(Now) <= Sheets("Optics Report").Range("L" & (r + 4)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("R" & (r + 4)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("L" & (r + 3)).Value)
If Int(Now) <= Sheets("Optics Report").Range("L" & (r + 3)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("R" & (r + 3)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("K" & (r + 4)).Value)
If Int(Now) <= Sheets("Optics Report").Range("K" & (r + 4)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("Q" & (r + 4)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("K" & (r + 3)).Value)
If Int(Now) <= Sheets("Optics Report").Range("K" & (r + 3)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("Q" & (r + 3)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("J" & (r + 4)).Value)
If Int(Now) <= Sheets("Optics Report").Range("J" & (r + 4)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
Else
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("J" & (r + 3)).Value)
If Int(Now) <= Sheets("Optics Report").Range("J" & (r + 3)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
End If
ElseIf Sheets("Optics Report").Range("Q" & (r + 1)).Value <> "" Then
If Sheets("Optics Report").Range("T" & (r + 2)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Sheets("Optics Report").Range("T" & (r + 2)).Value - Sheets("Optics Report").Range("M" & (r + 2)).Value)
If Sheets("Optics Report").Range("T" & (r + 2)).Value <= Sheets("Optics Report").Range("M" & (r + 2)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("T" & (r + 1)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("M" & (r + 2)).Value)
If Int(Now) <= Sheets("Optics Report").Range("M" & (r + 2)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("S" & (r + 2)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("M" & (r + 1)).Value)
If Int(Now) <= Sheets("Optics Report").Range("M" & (r + 1)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("S" & (r + 1)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("L" & (r + 2)).Value)
If Int(Now) <= Sheets("Optics Report").Range("L" & (r + 2)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("R" & (r + 2)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("L" & (r + 1)).Value)
If Int(Now) <= Sheets("Optics Report").Range("L" & (r + 1)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("R" & (r + 1)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("K" & (r + 2)).Value)
If Int(Now) <= Sheets("Optics Report").Range("K" & (r + 2)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("Q" & (r + 2)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("K" & (r + 1)).Value)
If Int(Now) <= Sheets("Optics Report").Range("K" & (r + 1)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("Q" & (r + 1)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("J" & (r + 2)).Value)
If Int(Now) <= Sheets("Optics Report").Range("J" & (r + 2)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
Else
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("J" & (r + 1)).Value)
If Int(Now) <= Sheets("Optics Report").Range("J" & (r + 1)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
End If
Else
If Sheets("Optics Report").Range("T" & r).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Sheets("Optics Report").Range("T" & r).Value - Sheets("Optics Report").Range("M" & r).Value)
If Sheets("Optics Report").Range("T" & r).Value <= Sheets("Optics Report").Range("M" & r).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("T" & (r - 1)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("M" & r).Value)
If Int(Now) <= Sheets("Optics Report").Range("M" & r).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("S" & r).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("M" & (r - 1)).Value)
If Int(Now) <= Sheets("Optics Report").Range("M" & (r - 1)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("S" & (r - 1)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("L" & r).Value)
If Int(Now) <= Sheets("Optics Report").Range("L" & r).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("R" & r).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("L" & (r - 1)).Value)
If Int(Now) <= Sheets("Optics Report").Range("L" & (r - 1)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("R" & (r - 1)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("K" & r).Value)
If Int(Now) <= Sheets("Optics Report").Range("K" & r).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("Q" & r).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("K" & (r - 1)).Value)
If Int(Now) <= Sheets("Optics Report").Range("K" & (r - 1)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
ElseIf Sheets("Optics Report").Range("Q" & (r - 1)).Value <> "" Then
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("J" & r).Value)
If Int(Now) <= Sheets("Optics Report").Range("J" & r).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
Else
Sheets("Optics Report").Range("AD" & (r - 1) & ":AD" & (r + 6)).Value = Abs(Int(Now) - Sheets("Optics Report").Range("J" & (r - 1)).Value)
If Int(Now) <= Sheets("Optics Report").Range("J" & (r - 1)).Value Then
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "<"
Else
Sheets("Optics Report").Range("AC" & (r - 1) & ":AC" & (r + 6)).Value = "="
End If
End If
End If
r = r + 8
Loop
End If
End Sub
Like I said, I know this is a ton of code, but it's actually not all that bad. There are three major if statements. One of them is at the very beginning of the sub:
Code:
If Sheets("Optics Report").Range("J" & (r - 1)).Value <> "" Then
The second is almost immediately after it:
Code:
If Sheets("Optics Report").Range("Q" & (r + 5)).Value <> "" Then
which is supposed to have two elseif statements and an else. I think this is written correctly, but I could have missed something.
The third if statement:
Code:
If Sheets("Optics Report").Range("T" & (r + 6)).Value <> "" Then
is inside the second if, and is repeated in both of the elseifs and the else, just with a different value in the cell reference.
I'm sure this is asking a lot to sift through this, but I've been working on this for almost a full week and still haven't gotten it to work. I'm all tapped out of ideas, and would appreciate a new set of eyes to look over it sooo much.
FYI, when I run the code as is it simply does absolutely nothing to the sheet.
Thanks for the looks everyone. Igreatly appreciate the help.
Hank