开发者

How do I check if an Excel cell's Date is within one week?

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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜