excelmania087
New Member
- Joined
- May 15, 2010
- Messages
- 44
- Office Version
- 365
- Platform
- 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:
However i find it hard to change the formula for my case.
Thank You very much for helping me.
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.