You can use the DateAdd function in VBA with a negative number to subtract a specific number of days from a date.
Here is one common way to use this function in practice:
Sub SubtractDays()
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 subtract four days from 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 subtract days to the dates as opposed to another unit of time.
Refer to the VBA documentation page 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: Subtract Days from Date in VBA
Suppose we have the following list of dates in Excel:
Suppose we would like to subtract four days from each date and display the new dates in column B.
We can create the following macro to do so:
Sub SubtractDays()
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:
Notice that column B contains each of the dates in column A with four days subtracted from them.
Feel free to change the numeric value in the DateAdd function to subtract a different number of days from each date.
Note: You can find the complete documentation for the DateAdd function in VBA here.
Additional Resources
The following tutorials explain how to perform other common tasks in VBA:
How to Compare Dates in VBA
How to Convert String to Date in VBA
How to Calculate Days Between Two Dates in VBA