如何检查 Excel 单元格的日期是否在一周内?

发布于 2024-09-16 02:24:55 字数 284 浏览 1 评论 0原文

我正在Excel 2010中使用VBA制作一个简单的生日提醒程序。我有一列日期(D 列)。如何检查某个单元格是否在今天之后的一周内?

我不确定条件语句的 VBA 语法是什么:

For i = 2 To MAX_ROW
    cell = ActiveSheet.Cells(i, 4)
    If (Date(cell) - Date(Now()) <= 7) Then
      MsgBox(ActiveSheet.Cells(i, 1)
    End If
Next

I'm using VBA in Excel 2010 to make a simple birthday reminder program. I have a column of dates (Column D). How do I check if a cell is within one week of today?

I'm not sure what the VBA syntax for the conditional statement would be:

For i = 2 To MAX_ROW
    cell = ActiveSheet.Cells(i, 4)
    If (Date(cell) - Date(Now()) <= 7) Then
      MsgBox(ActiveSheet.Cells(i, 1)
    End If
Next

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看春风乍起 2024-09-23 02:24:55

如果单元格包含实际的生日,您需要将年份更改为当前年份,例如:

If DateSerial(Year(Date), Month(Cell), Day(Cell)) - Date <= 7 Then

If the cells contain actual birthdays, you will need to change the year to the current year, say:

If DateSerial(Year(Date), Month(Cell), Day(Cell)) - Date <= 7 Then
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文