How to Find and Insert Missing Hourly Records in Excel
Question details
Identify missing hourly timestamps in a year-long dataset and accurately insert blank rows or filled time values to correct the chronological sequence.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Managing a full year's continuous hourly dataset (which should contain 8,760 values) where some hourly timestamps are missing due to system recording failures.
- Observed behavior
- The dataset skips missing hours entirely without leaving blank spaces, currently forcing the user to find gaps and add missing rows manually.
Always create a backup copy of your workbook before running VBA macros that insert or delete rows, as macro actions typically cannot be undone using the standard Undo feature.
Use a VBA Macro to Automatically Insert Missing Hours
A VBA macro is the most efficient way to loop through thousands of rows, detect time gaps greater than one hour, and automatically insert the missing timestamps.
By comparing adjacent timestamps from the bottom of your dataset to the top, a VBA macro can identify gaps efficiently. Once a gap exceeding one hour is found, the script inserts a new row and populates it using the DateAdd function.
Press 'Alt + F11' in Excel to open the Visual Basic for Applications (VBA) editor, then click 'Insert' > 'Module' from the top menu to create a new blank script window.
Write a script that loops backwards (e.g., For i = LastRow To 2 Step -1). Inside the loop, use the 'DateDiff' function in VBA to compare the timestamp in cell(i) with cell(i-1).
If the difference is greater than 60 minutes, use 'Rows(i).EntireRow.Insert' to add a new row. Use the 'DateAdd' function to add exactly one hour to the preceding timestamp and place it in the newly created blank cell.
Close the VBA editor and return to your worksheet. Go to the 'Developer' tab, click 'Macros', select your newly created macro, and click 'Run'.
Identify Missing Records Using a Helper Formula
If you prefer not to use VBA, you can use a formula to calculate exactly how many hours are missing between consecutive rows, allowing you to manually insert the correct number of rows.
Manage Large Datasets and Macros Easily with WPS Spreadsheet
WPS Office offers a highly capable Spreadsheet application that fully supports advanced formulas and VBA macros, making it incredibly simple to identify gaps and fill missing hourly records in massive yearly datasets.
- 1. Download and Open: Install WPS Office for free and open your hourly dataset file (.xlsx or .csv) in WPS Spreadsheet.
- 2. Access the Developer Tools: Navigate to the Developer tab on the top ribbon to easily access the VBA Editor and manage your macros.
- 3. Automate the Process: Input your time gap macro or helper formulas directly, executing the gap-filling process seamlessly just like you would in Excel.

Frequently Asked Questions
How many hourly records should a standard one-year dataset contain?
A standard non-leap year contains exactly 8,760 hourly records (365 days multiplied by 24 hours). If it is a leap year, the dataset will contain 8,784 records.
Why does my time calculation formula return a #VALUE! error?
This error occurs if your timestamp column is formatted as text instead of Date/Time. The software requires numeric date-time values to perform mathematical operations. Select the column, go to 'Format Cells', and change the type to a Custom Date/Time format.
Can I automatically estimate the data values for the missing hours?
Yes. Once the blank rows are inserted, you can use linear interpolation formulas to estimate the missing data points by calculating the average between the preceding and succeeding known values. VBA can also be programmed to do this automatically during row insertion.




