英文:
Delete the contents of the cell in case of type-mismatch error
问题
我想检查日期并收集超过1年的日期数量。但问题是在检查的列中不仅有正确的日期,例如:2022.04-05(四月-五月)或文本,所以在CDate
的情况下我会得到类型不匹配的错误。是否有可能在出现类型不匹配错误的情况下删除单元格内容而不中断宏?我的意思是,如果CDate
不可行,删除单元格的内容。谢谢!
英文:
I would like to check dates and collect how many are older than 1 year. But the problem is that in the examined column are not only correct dates, for example: 2022.04-05 (april-may) or text, so in case of CDate
I get type-mismatch error. Is there any possibility to delete cells in case of type-mismatch error without interrupting the macro? I mean if CDate
is not possible, delete the contents of the cell. Thank you!
答案1
得分: 0
使用 IsDate
函数:
> 如果表达式是日期或可识别为有效日期或时间,则返回 True;否则返回 False。
If IsDate(cell.Value) Then
' 收集超过1年的数量
Else
cell.ClearContents
End If
英文:
Using IsDate
:
> Returns True if the expression is a date or is recognizable as a valid date or time; otherwise, it returns False.
If IsDate(cell.Value) Then
' collect how many are older than 1 year
Else
cell.ClearContents
End If
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论