如何在Excel中的列中添加缺失时间以进行插值

时间:2017-10-19 23:46:29

标签: excel

我有一个Excel电子表格,其中包含两列数据,如时间和温度。时间列具有如下值,其中有一些跳过的秒:

2017-10-17 14:18:15    
2017-10-17 14:18:17    
2017-10-17 14:18:18    
2017-10-17 14:18:19    
2017-10-17 14:18:21    
2017-10-17 14:18:22

是否可以让Excel在缺少的时间内添加相应的空行(这样我就可以对这些空白点进行插值?)

2 个答案:

答案 0 :(得分:1)

我不确定您的数据是什么样的,但如果您不想使用VBA,则可以执行此操作。

使用ui->nodesTable->item(-1, 0)中的此公式并向下拖动:

cell B2

这样做是为了确定最大值和最小值之间的秒数,然后使用行作为参考(您可以根据数据结构更改此部分)。试着看看这是否适合你。

答案 1 :(得分:0)

试试这个!它假定您的时间在A列中,在单元格A1中有标题

Sub AddRows()

'Finds out what row to go up to
 Dim lRow As Long
 lRow = Cells(Rows.Count, 1).End(xlUp).Row

 For i = 2 To lRow + 1

'If the difference between the cell below is more than a second, then add a 
row above and skip the next i
If Cells(i + 1, 1) - Cells(i, 1) > 0.000011575 Then
   Cells(i + 1, 1).Select
   Selection.EntireRow.Select
   Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
   lRow = lRow + 1
   Cells(i + 1, 1).Select
   Cells(i + 1, 1).Value = Cells(i, 1).Value + 0.000011575
   i = i + 1

Else

End If

Next i

End Sub