在过期的macros中,我的错误是什么? 返回的值是一个时间格式

下面是Sub计算两个date之间的年份。 单元格(i,3)中没有显示任何值,当我更新到MsgBox时,显示时间值。 先谢谢您的帮助。

Sub EE_DatedIF() Dim wb1 As Workbook Dim i As Long Dim LastRow1 As Long Dim yrDiff As Long Dim d1 As Date Dim d2 As Date Set wb1 = Workbooks("macro all client v.01.xlsm") LastRow1 = wb1.Sheets("Carrier").range("E:E").Find("", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row For i = 10 To LastRow1 d1 = wb1.Sheets("Settings").Cells(i, 1) d2 = wb1.Sheets("Carrier").Cells(i, 24) yrDiff = DateDiff("yy", d1, d2) wb1.Sheets("Settings").Cells(i, 3) = yrDiff Next i End Sub 

在其他问题中,您尝试检索E列中最后一个已填充的行不应视为可靠。 更接近这个更好的东西。

 With wb1.Sheets("Carrier").Range("E:E") lastRow1 = .Find("*", after:=.Cells(1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row End With