![]() Let’s assume that we have a date value of and we want look at the following scenarios, namely:Ģ) What is the date if we subtract a weekĭim DateToProcess As Date’Variable to hold the date valueĭateToProcess = ActiveSheet.Cells(2, 1).Value’Assign the date value to our variableĪctiveSheet.Cells(6, 1).Value = DateAdd(“yyyy”, 1, DateToProcess)ĪctiveSheet.Cells(8, 1).Value = DateAdd(“ww”, -1, DateToProcess)ĪctiveSheet.Cells(10, 1). Number = The values that we want to add or substract ![]() If we want to work with weeks we would use the ‘ww’ attribute. For example if we want to work with years we would use the ‘yyyy’ attribute. Interval= The frequency type that you want to work with. You can use it for example to add or subtract days from a date you are working with. Below is the code to change the date format. We can also change the date format by using the FORMAT function. ![]() Run the code using the F5 key or manually and see what the result is. The Excel DateAdd function is used to perform some interesting date arithmetic. Code: Sub NowExample1 () Dim k As Date k Now MsgBox k End Sub. Excel DateAdd Function: Add or Subtract Days from a Date
0 Comments
Leave a Reply. |