Inserting rows for Missing Date/ Time data (Excel 2007)

mzalikhan

Board Regular
Joined
May 16, 2011
Messages
62
Hi everybody

I have got an hourly data for 10 years. The problem is that some of the data is missing. I need to insert new rows for the missing hours and put the "date hour" in the respective column. For example what i have is column A as
A
1/1/2000 00:30 AM
1/1/2000 01:30 AM
1/1/2000 02:30 AM
1/1/2000 04:30 AM
1/1/2000 05:30 AM

Please note that in 4th row, it should be 1/1/2000 03:30, which is missing. So what i need to have is

1/1/2000 00:30 AM
1/1/2000 01:30 AM
1/1/2000 02:30 AM
1/1/2000 03:30 AM
1/1/2000 04:30 AM
1/1/2000 05:30 AM

By the way data starts from 2000 and ends at 2010.

Peace
Muhammad Zeeshan
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this with a copy of your sheet

Code:
Sub Missing()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    If CLng((Range("A" & i).Value - Range("A" & i - 1).Value) * 24) <> 1 Then
        Rows(i).Insert
        Range("A" & i).Value = Range("A" & i - 1).Value + 1 / 24
    End If
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Vog

Thanks for the code. I just tried it its not working. On clicking debug option, it gives a hint of following problem.

If CLng((Range("A" & i).Value - Range("A" & i - 1).Value) * 24)= <Type Mismatch>

I don't understand much about this thing. Can you please see it again?

Peace
 
Upvote 0
By the way it is inserting some empty cells.... but... after every 23:30, it inserts 00:30 then again 23:30 and 00:30 and moves forward normally.
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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