fill in Date and time where missing on 3 minute interval.

Albert_A

New Member
Joined
Jul 20, 2012
Messages
2
Hi

I am having trouble getting a VBA code to do the following:

2012/05/01 00:00:00
2012/05/01 00:03:00
2012/05/01 00:06:00
2012/05/01 00:15:00
2012/05/01 00:18:00

From this above to this below

2012/05/01 00:00:00
2012/05/01 00:03:00
2012/05/01 00:06:00
2012/05/01 00:09:00

2012/05/01 00:12:00
2012/05/01 00:15:00
2012/05/01 00:18:00

There are data entries next to these time stamps. I am able to create just the time stamps starting at the beginning and ending at the end of the month but I need it to fill in missing entries in a data set. The code below works but only some of the time. I have tried a few different things but nothing works.


Code:
Sub Insert_missing_3min()
'Inserts a row with the date and time where the missing date and time stamp is and a zero next to the date added.


    Dim min3 As Date
    Dim CurTime As Date
    Dim CurCell As Date
    Dim NextCell As Date
    
    
        
        
    min3 = 3 / 24 / 60
        
    If (Hour(ActiveCell) <> 0 Or Minute(ActiveCell) <> 0 Or Day(ActiveCell) <> 1) Then      'makes the start date the fisrt of the month at 00:00
      ActiveCell.EntireRow.Insert
      ActiveCell.Value = Year(ActiveCell.Offset(1, 0)) & "/" & Month(ActiveCell.Offset(1, 0)) & "/" & "16"
                      
    End If
    
    Maand = Month(ActiveCell)
    
   Do While IsDate(ActiveCell) And Month(ActiveCell) = Maand
   
            CurTime = DateValue(ActiveCell) + TimeValue(ActiveCell)
            CurCell = TimeValue(ActiveCell)
            NextCell = DateValue(ActiveCell.Offset(1, 0)) + TimeValue(ActiveCell.Offset(1, 0))
            
                        
            If (NextCell <> (CurCell + min3)) Then
                ActiveCell.Offset(1).EntireRow.Insert
                ActiveCell.Offset(1, 0).Activate
                ActiveCell.Value = CurTime + min3    '3 min time value in excell
                ActiveCell.Offset(0, 1).Value = 0                     ' Value in colum next to date 0
                With Selection.Interior                                 ' Highlight
                    .Pattern = xlSolid
                    .PatternColorIndex = xlAutomatic
                    .Color = 65535
                    .TintAndShade = 0
                    .PatternTintAndShade = 0
                End With
            Else
                ActiveCell.Offset(1, 0).Activate
            End If
    Loop


End Sub



Thank you :)
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top