我试图遍历“ G”列中的到期日期,并将它们与今天的日期进行比较。每当我运行该代码时,该代码就会循环363次,但是它在ExpirationDate = Cells(x, "G").Value
处停止,并给我一个类型不匹配的错误。
“ G”列中的所有单元格都标记为日期,ExpirationDate也是如此。在代码始终停止的行和成功通过代码的行之间,我看不出有什么区别。
For x = 13 To numrows
reminderrows = Worksheets("Reminders").Cells(Rows.Count, "A").End(xlUp).Row
expiredrows = Worksheets("Expired").Cells(Rows.Count, "A").End(xlUp).Row
Worksheets("Training Log Test").Activate
ExpirationDate = Cells(x, "G").Value
If ExpirationDate > today And ExpirationDate <= ninetydays Then
Rows(x).Copy
Worksheets("Reminders").Activate
Worksheets("Reminders").Cells(reminderrows + 1, 1).Select
ActiveSheet.Paste
ElseIf today >= ExpirationDate Then
Rows(x).Copy
Worksheets("Expired").Activate
Worksheets("Expired").Cells(expiredrows + 1, 1).Select
ActiveSheet.Paste
Else
End If
Next
End Sub
答案 0 :(得分:0)
请尝试替换以下行:
ExpirationDate = Cells(x, "G").Value
与此:
ExpirationDate = Cells(x,7).Value