Thank you for Visiting my Blog

Sunday, 6 August 2017

How Day function works in VBA and EXCEL


Description:
The DAY function is a built-in function in Excel that is categorized as a Date/Time Function. It can be used as a worksheet function (WS) and a VBA function (VBA) in Excel. As a worksheet function, the DAY function can be entered as part of a formula in a cell of a worksheet. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.

Syntax:
Day(date)

The required date argument is any Variant, numeric expression, string expression, or any combination, that can represent a date. If date contains Null, Null is returned.

 Note :
If the Calendar property setting is Gregorian, the returned integer represents the Gregorian day of the month for the date argument. If the calendar is Hijri, the returned integer represents the Hijri day of the month for the date argument.


Example:

This example uses the Day function to obtain the day of the month from a specified date. In the development environment, the date literal is displayed in short format using the locale settings of your code.

Sub DAY_FN()

Dim MyDate, MyDay

MyDate = #8/6/2017#   
' Assign a date.

MyDay = Day(MyDate)   
' MyDay contains 6.
MsgBox (MyDay)

End Sub

Output:

 Below is the example how to use DAY function in Excel:




You may like to visit :

No comments:

Post a Comment