Help: how do identify the missing dates and fill in the missing data

excelmania087

New Member
Joined
May 15, 2010
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hello everyone. I have quite a big problem with finding the missing dates and appropriate values.
There is data with the results of measurements from 1980-11-13 to 2010-05-31 (in the column A) represented in 3 other columns (B, C and D). Each date has three values of figures adjacent to it (shown in columns B, C and D (the sum of the values in B and C). The measurements are taken once daily (not twice, thrice, etc.). The values in column D are the sum of the values in columns C and D.
Could someone, please, help me writting a macro for finding the missing dates and values. I suppose, it should be quite similar to the one posted below:

Code:
Sub Interpolate_Missing_Data()

    Dim i As Long, NumbMissing As Integer, NextDateTime As Date, interp As Double
    
    With Application
        .ScreenUpdating = False
        
        For i = Range("A" & Rows.Count).End(xlUp).Row - 1 To 2 Step -1
        
            NumbMissing = ((.Sum(Range("A" & i + 1).Resize(, 2)) - .Sum(Range("A" & i).Resize(, 2))) / 0.5) - 1
            If NumbMissing > 0 Then
            
                interp = (Range("C" & i + 1) - Range("C" & i)) / (NumbMissing + 1)
                Range("A" & i + 1).Resize(NumbMissing, 4).Insert Shift:=xlDown
                For ii = 1 To NumbMissing
                
                    NextDateTime = Range("A" & ii + i - 1) + Range("B" & ii + i - 1) + 0.5
                    Range("A" & ii + i) = Int(NextDateTime)
                    Range("B" & ii + i) = NextDateTime - Int(NextDateTime)
                    Range("C" & ii + i) = .Round(Range("C" & ii + i - 1) + interp, 1)
                    Range("D" & ii + i) = "Interpolated"
                Next ii
            End If
        Next i
        
        .ScreenUpdating = True
    End With
    
End Sub</pre>

However i find it hard to change the formula for my case.
Thank You very much for helping me. :smile:
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
In a different sheet, create all the dates possible. Just type the first date, and "+1" below it. Do a VLOOKUP for each date. Sort by the errors, and then you have your missing dates.
 
Upvote 0
In a different sheet, create all the dates possible. Just type the first date, and "+1" below it. Do a VLOOKUP for each date. Sort by the errors, and then you have your missing dates.

Could you, please, explain this method more in detail? I haven't worked with macros for quite a long time and now it is hard for me to write it. Thank you. ;)
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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