Saturday, October 27, 2012

How to Find Number of Days, Weeks, Months, Quarter In the Given Date Year using Excel VBA Macro

Excel VBA Macro To Know Number of Days, Weeks, Months, Quarter In the Given Date Year.
You can also know the Names of the Days, Weeks, Months In the Given Date

Sub MyYear_Month_DayNames()
Dim X As String
Dim Y As String

X = #10/24/2012#

'To Know Week Number (Eg: 4th Week) In the Current Year as of Given Date
Y = Weekday(X)
MsgBox "Week No.of The Month In Given Date " & " " & X & " " & " Is: " & Y

'To Know  Weekday Name of the Given Date
Y = WeekdayName(Weekday(X))
MsgBox "Week Name of The Month In Given Date " & " " & X & " " & " Is: " & Y

'To Know Month Number of the Given Date
Y = Month(X)
MsgBox "Month Number of The Month In Given Date " & " " & X & " " & " Is: " & Y


'To Know Month Name of the Given Date
Y = MonthName(Month(X))
MsgBox "Month Name of The Month In Given Date " & " " & X & " " & " Is: " & Y

'To Know Year of the Given Date
Y = Year(X)
MsgBox "Year of The Given Date " & " " & X & " " & " Is: " & Y

'To Know No. of Days of the Given Date
Y = Day(X)
MsgBox "The No. of Days in Given Date" & "  " & X & " Are: " & Y

'To Know Current Quarter of the Year as of Given Date
Y = DatePart ("Q", X)
MsgBox "The Current Quarter of the Year In Given Date" & "  " & X & " Is: " & Y

End Sub

Thanks,Tamatam

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog