Q:

Subtracting two cells based on values in another cell in Excel

I'm trying to calculate the duration of presence of animals that are photographed by an motion-sensitive camera every few seconds as long as there is activity in front of the camera.  We make the assumption that if the animals are not present for 6 minutes, we consider it a new occurrence of animals and new data point.  
I'm trying to create a macro that will calculate the duration of time in which animals are present in front of the camera. Here is an example, where I want to subtract the value in with ** two stars ** from the value several records higher with * one star *. I put #hash-marks# around the Difference of Time values that are greater than 6 minutes for ease of reading.
 Photo # Date       Time        Difference of time     Duration of visit
    1   2/9/2012   *8:01:30 PM*      NA                      0:08:48                    
    2   2/9/2012    8:01:31 PM      0:00:01         
    3   2/9/2012    8:01:36 PM      0:00:05         
    4   2/9/2012    8:01:54 PM      0:00:18         
    5   2/9/2012    8:02:36 PM      0:00:42         
    6   2/9/2012    8:02:48 PM      0:00:12         
    7   2/9/2012    8:03:07 PM      0:00:19         
    8   2/9/2012    8:03:23 PM      0:00:16         
    9   2/9/2012    8:04:18 PM      0:00:55         
    10  2/9/2012    8:04:42 PM      0:00:24         
    11  2/9/2012    8:05:02 PM      0:00:20         
    12  2/9/2012    8:05:52 PM      0:00:50         
    13  2/9/2012    8:07:08 PM      0:01:16         
    14  2/9/2012    8:08:59 PM      0:01:51         
    15  2/9/2012    8:10:09 PM      0:01:10         
    16  2/9/2012  **8:10:18 PM**    0:00:09         
    17  2/9/2012   *8:18:08 PM*    #0:07:50#                0:01:22     
    18  2/9/2012    8:18:11 PM      0:00:03         
    19  2/9/2012    8:18:23 PM      0:00:12         
    20  2/9/2012    8:18:34 PM      0:00:11         
    21  2/9/2012  **8:19:30 PM**    0:00:56         
    22  2/10/2012  *8:36:51 AM*   #12:17:21#                0:01:44     
    23  2/10/2012   8:38:00 AM      0:01:09         
    24  2/10/2012   8:38:06 AM      0:00:06         
    25  2/10/2012   8:38:08 AM      0:00:02         
    26  2/10/2012   8:38:17 AM      0:00:09         
    27  2/10/2012   8:38:33 AM      0:00:16         
    28  2/10/2012 **8:38:35 AM**    0:00:02         
    29  2/12/2012   9:15:00 AM     #0:36:25#                     X      

I've worked from several examples including this one on copying based on other cell values, this one that sums certain rows if conditions are met, and possibly the closest, this one that adds and subtracts values based on values in other cells.  I developed the following draft macro, but I'm new to VBA and can't get the pieces to fit together. 
Sub CalculateDuration()

Dim duration As Date

'I basically want this to mean search down row D (Difference of time column) for values that are greater than 6 minutes

duration = Cells(Rows.Count, "D").End(xlUp).Row
    For Each cell In Range("D:D")
        If cell.Value >= Range("G2").Value Then

'Cell G2 has the 6 minute value in it (i did it this way since it's set as a time value) although I could also add a 00:06:00 if that would work.

              ActiveCell.Offset(0, 1).Value = X - ActiveCell.Offset(0, -1).Value

              'I need to point the value of X to be the next value in column C that is just one row higher than the next value in Column D that's >= 0:06:00 minutes. I'm not sure the best way to go about that... perhaps a nested if/then?

'I also think I may need something to make this write or end properly...

              End If
    Next

End Sub

Thanks in advance for any help you can offer.

A:

It's not using VBA, but the formulas could be adopted and inserted into VBA code.
This is my result:

Columns A, B, C are the data.
Cell D2:
=B2+C2

Cell E2:
=IF(ROW(D2)=2,0,D2-D1)

Cell F2:
=IF(ROW(A2)=2,1,IF(E2<6/60/24,F1,F1+1))

Cell G2:
=IF(F2=F1,"",INDEX($D$2:$D$30,MATCH(F2+1,$F$2:$F$30,0)-1)-INDEX($D$2:$D$30,MATCH(F2,$F$2:$F$30,0)))

