I really don't know what to make of this...
I have a list of thousands of dates and times in chronological order. Here is a short example:
9/14/09 15:08:00
9/14/09 15:09:00
9/14/09 15:12:00
9/14/09 15:13:00
9/14/09 15:15:00
9/15/09 9:09:00
9/15/09 9:10:00
9/15/09 9:11:00
9/15/09 9:13:00
9/15/09 9:14:00
9/15/09 9:16:00
9/15/09 9:17:00
Note that there are minutes missing and the dates change. I need to fill in the missing minutes for each date but not the minutes between dates. Here is an example of what I need for my result based on the above example (added dates indicated with * for clarity)
9/14/09 15:08:00
9/14/09 15:09:00
9/14/09 15:10:00*
9/14/09 15:11:00*
9/14/09 15:12:00
9/14/09 15:13:00
9/14/09 15:14:00*
9/14/09 15:15:00
9/15/09 9:09:00
9/15/09 9:10:00
9/15/09 9:11:00
9/15/09 9:12:00*
9/15/09 9:13:00
9/15/09 9:14:00
9/15/09 9:15:00*
9/15/09 9:16:00
9/15/09 9:17:00
So I have written a macro that starts from the bottom of the list and checks to see if the time in the cell above is the next minute. If not, the macro inserts a row and adds the missing time (ideally in red text but I haven't gotten that far yet). The idea is that I work my way up adding the missing minutes. If the date changes, the information is reset to the new date and time and the process continues.
Here is the code...
Sub AddRow()
'
' AddRow Macro
' Macro recorded 11/1/2009 by Scott Evans
'
'
Dim vDate As Single
Dim vTime As Date
Dim inc_min As Date
inc_min = 0.00069444444
vDate = Int(ActiveCell.Value)
vTime = ActiveCell.Value - inc_min
Do Until IsEmpty(ActiveCell)
'Checks date and resets info
If Int(ActiveCell.Offset(-1, 0).Value) <> vDate Then
vDate = Int(ActiveCell.Value)
vTime = ActiveCell.Value
End If
'Checks in next minute is as expected if not, add row
If ActiveCell.Offset(-1, 0).Value <> vTime Then
Selection.EntireRow.Insert
ActiveCell.Value = vTime
vTime = vTime - inc_min
End If
vTime = vTime - inc_min
ActiveCell.Offset(-1, 0).Range("A1").Select
Loop
End Sub
So I have this really strange problem with the IF/THEN loop that inserts the row. On the dataset above, it works fine the first time through. But after it encounters its first missing minutes, the IF/THEN loop is always triggered even if the values are equal!!
I am totally stumped. I tried dimensioning the variables differently, I tried using the exact value for the min_inc variable (60/86400) since the result is irrational. I can't figure out why the IF/THEN loop is triggered.
If anyone can provide some help on this one, it would be greatly appreciated.
I have a list of thousands of dates and times in chronological order. Here is a short example:
9/14/09 15:08:00
9/14/09 15:09:00
9/14/09 15:12:00
9/14/09 15:13:00
9/14/09 15:15:00
9/15/09 9:09:00
9/15/09 9:10:00
9/15/09 9:11:00
9/15/09 9:13:00
9/15/09 9:14:00
9/15/09 9:16:00
9/15/09 9:17:00
Note that there are minutes missing and the dates change. I need to fill in the missing minutes for each date but not the minutes between dates. Here is an example of what I need for my result based on the above example (added dates indicated with * for clarity)
9/14/09 15:08:00
9/14/09 15:09:00
9/14/09 15:10:00*
9/14/09 15:11:00*
9/14/09 15:12:00
9/14/09 15:13:00
9/14/09 15:14:00*
9/14/09 15:15:00
9/15/09 9:09:00
9/15/09 9:10:00
9/15/09 9:11:00
9/15/09 9:12:00*
9/15/09 9:13:00
9/15/09 9:14:00
9/15/09 9:15:00*
9/15/09 9:16:00
9/15/09 9:17:00
So I have written a macro that starts from the bottom of the list and checks to see if the time in the cell above is the next minute. If not, the macro inserts a row and adds the missing time (ideally in red text but I haven't gotten that far yet). The idea is that I work my way up adding the missing minutes. If the date changes, the information is reset to the new date and time and the process continues.
Here is the code...
Sub AddRow()
'
' AddRow Macro
' Macro recorded 11/1/2009 by Scott Evans
'
'
Dim vDate As Single
Dim vTime As Date
Dim inc_min As Date
inc_min = 0.00069444444
vDate = Int(ActiveCell.Value)
vTime = ActiveCell.Value - inc_min
Do Until IsEmpty(ActiveCell)
'Checks date and resets info
If Int(ActiveCell.Offset(-1, 0).Value) <> vDate Then
vDate = Int(ActiveCell.Value)
vTime = ActiveCell.Value
End If
'Checks in next minute is as expected if not, add row
If ActiveCell.Offset(-1, 0).Value <> vTime Then
Selection.EntireRow.Insert
ActiveCell.Value = vTime
vTime = vTime - inc_min
End If
vTime = vTime - inc_min
ActiveCell.Offset(-1, 0).Range("A1").Select
Loop
End Sub
So I have this really strange problem with the IF/THEN loop that inserts the row. On the dataset above, it works fine the first time through. But after it encounters its first missing minutes, the IF/THEN loop is always triggered even if the values are equal!!
I am totally stumped. I tried dimensioning the variables differently, I tried using the exact value for the min_inc variable (60/86400) since the result is irrational. I can't figure out why the IF/THEN loop is triggered.
If anyone can provide some help on this one, it would be greatly appreciated.