The VBA DAY function is listed under the date and time category of VBA functions. When you use it in a VBA code, it returns the value from the date which you supplied. As you know a valid VBA date is made up of the day, month, and year so it takes the day and ignores the rest of the part. It’s just like the DAY function in the worksheet.
- Date: A valid date as per VBA from which you want to get the day.
To practically understand how to use VBA DAY function, you need to go through the below example where we have written a vba code by using it:
Sub example_DAY() Range("B1").Value = Day(Range("A1")) End Sub
In the above example, we have used DAY to get the day number from the date which we have in the cell A1 and it has returned the 15 in the result as the date is the 15-May-19.
- If the value specified is a value other than a date or a date that can’t be recognized as a date, VBA will return the run-time 13 error.
- And if the date is NULL, it will return NULL.