excelmacros不能识别我的第二个中频条件

我有以下代码来检查从E15开始的单元格是否与当天date相比具有超过45天的date不同,这里的问题是它不能识别以下情况,并且它将返回错误,下面是检查如果单元格的值是date。 有什么不对的下面,如果条件?

IsDate(.Range("E" & i)) = True Sub Refees() Dim ws As Worksheet Dim lRow As Long, i As Long, OutputRow As Long Dim copyRng As Range '~~> Change this to the relevant worksheet Set ws = ActiveWorkbook.Sheets("Warranty Quote 1 Year") With ws '~~> Get LatRow in Col B lRow = .Range("B" & .Rows.Count).End(xlUp).Row OutputRow = lRow + 1 '~~> Loop through the cells For i = 15 To lRow If DateDiff("d", .Range("E" & i).Value, Date) > 45 And IsDate(.Range("E" & i)) = True Then If copyRng Is Nothing Then Set copyRng = .Range("B" & i & ":I" & i) Else Set copyRng = Union(copyRng, .Range("B" & i & ":I" & i)) End If End If Next i '~~> Copy the expired records in one go If Not copyRng Is Nothing Then copyRng.Copy .Range("B" & OutputRow) lRow = .Range("B" & .Rows.Count).End(xlUp).Row .Range("I" & OutputRow & ":I" & lRow).Value = "Reinstatement Fees" End If End With End Sub 

尝试改变你的代码(首先检查它是否是一个date):

 For i = 15 To lRow If IsDate(.Range("E" & i)) = True Then If DateDiff("d", .Range("E" & i).Value, Date) > 45 Then If copyRng Is Nothing Then Set copyRng = .Range("B" & i & ":I" & i) Else Set copyRng = Union(copyRng, .Range("B" & i & ":I" & i)) End If End If End If Next i