How to add days to a date in VBA?

Adding days to a date in VBA can be done by using the DateAdd() function. The DateAdd() function takes three parameters: the interval type (e.g. days), the number of intervals to add, and the date to which the intervals are to be added. The function then returns the result of the calculation, which is the new date after the intervals have been added.


You can use the DateAdd function in VBA to add a specific number of days to a date.

Here is one common way to use this function in practice:

Sub AddDays()

    Dim i As Integer
    
    For i = 2 To 10
        Range("B" & i) = DateAdd("d", 4, Range("A" & i))
    Next i
    
End Sub

This particular macro will add four days to each date in the range A2:A10 and display the new dates in the range B2:B10.

Note that the “d” argument in the DateAdd function specifies that we would like to add days to the dates as opposed to another unit of time.

Refer to the for a complete list of units you can use in the DateAdd function.

The following example shows how to use this syntax in practice.

Example: Add Days to Date in VBA

Suppose we have the following list of dates in Excel:

Suppose we would like to add four days to each date and display the new dates in column B.

We can create the following macro to do so:

Sub AddDays()

    Dim i As Integer
    
    For i = 2 To 10
        Range("B" & i) = DateAdd("d", 4, Range("A" & i))
    Next i
    
End Sub

When we run this macro, we receive the following output:

VBA add days to date

Notice that column B contains each of the dates in column A with four days added to them.

Feel free to change the numeric value in the DateAdd function to add a different number of days to each date.

x