0

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
4

1 に答える 1

1

セルに実際の誕生日が含まれている場合は、年を現在の年に変更する必要があります。たとえば、次のようにします。

If DateSerial(Year(Date), Month(Cell), Day(Cell)) - Date <= 7 Then
于 2010-08-21T22:49:16.300 に答える