Ok so I’ve done a good deal of searching found some and played and little. I cannot seem to get these loops to work fully I can get on part or another but not the whole. As is the first loop works fine then it goes wonky.
T is the destination for the expression output t.Value = time1 - time2
Y is a set time and date that does not change = time1
X is time and date and has to be extracted from the range in the same column as the corresponding y. x= time 2
I have uploaded the corresponding segment of my workbook :
https://docs.google.com/open?id=0BzGnV1BGYQbvMERWU3VkdGFTQS1tYXpXcU1Mc3lmUQ
I have played with conditional exits rearranging the for loops. I even considered trying goto until I noticed the large pile of bodies created by its very mention.
I am open to and grateful for any advice or direction. I noticed a few languages have exit and continue options but it does not appear VB does?
Here is the loop I have I have stripped out the mess I made while trying to get it to work.
Sub stituterangers()
Dim dify As Boolean
Dim difx As Boolean
Dim time2 As Date
Dim time1 As Date
For Each t In range("d7:cv7")
For Each x In range("d8:cv11")
If x > 0 Then time2 = x
For Each y In range("d2:cv2")
time1 = y
t.Value = time1 - time2
t = 0
Next y
Next x
Next t
End Sub
Sub stituterangersNEW()
Dim t As range
Dim x As range
Dim dify As Boolean
Dim difx As Boolean
Dim time2 As Date
Dim time1 As Date
On Error Resume Next
'Looping through each of our output cells.
For Each t In range("d7:cv7")
For Each y In range("d2:cv2")
If t.Column = y.Column Then
time1 = y.Value
If y = 0 Then Exit Sub
End If
For Each x In range("d8:cv11")
'Check to see if our dep time corresponds to
'the matching column in our output
If t.Column = x.Column Then
If x > 0 Then
time2 = x.Value
t.Value = time1 - time2
Exit For
End If
End If
Next x
Next y
Next t
End Sub