答案 0 :(得分:1)
答案 1 :(得分:0)
如果您尝试使用VBA实现此目的,假设您的日期在A2:A6范围内,尝试这样的事情......
Sub DateDif()
Dim lr As Long, i As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr - 1
If IsDate(Cells(i, 1)) And IsDate(Cells(i + 1, 1)) Then
Cells(i, 2) = DateDiff("d", Cells(i, 1), Cells(i + 1, 1))
End If
Next i
End Sub
或者尝试这样容易调整......
Sub DateDif()
Dim lr As Long
Dim Rng As Range, Cell As Range
lr = Cells(Rows.Count, "B").End(xlUp).Row
Set Rng = Range("B2:B" & lr)
For Each Cell In Rng
If IsDate(Cell) And IsDate(Cell.Offset(1, 0)) Then
Cell.Offset(0, 1) = DateDiff("d", Cell, Cell.Offset(1, 0))
End If
Next Cell
End Sub