Inserting rows for missing dates

smallsmallman

New Member
Joined
Jul 28, 2011
Messages
4
I have more than 8,000 rows of data in excel. It consists of wave and wind speeds on an hourly basis of the course of a year so there should be 8760 cells (the amount of hours in a year). However there are interruptions in the data as the wave buoy might have been inoperable for some hours or even days. I need the dates not to have any gaps in it, for a type of modeling I am doing, and was wondering if anybody knows how to insert a row where there is a missing time/date and insert the right time/date but with the information (wind/wave speeds) from the previous row

hope this makes sense!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try this?
Code:
Sub Test()
    'Assuming your data starts from A2
    
    Dim LR&, i&, prevDate#
    LR = Range("A" & Rows.Count).End(xlUp).Row
    prevDate = Range("A2").Value
    
    Application.ScreenUpdating = False
    For i = 2 To LR
        If Range("A" & i).Value = "" Then
            Range("A" & i).Value = Format$(prevDate + 1 / 24, "m/d/yyyy h:mm")
            Range("B" & i).Value = Range("B" & i - 1).Value
            Range("C" & i).Value = Range("C" & i - 1).Value
            Range("D" & i).Value = Range("D" & i - 1).Value
            Range("E" & i).Value = Range("E" & i - 1).Value
        End If
        prevDate = Range("A" & i).Value
    Next i
    
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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