I have already used this code: year() to get the current year. But, I only want the last two digits of the year. Foe example, from today's date 01/19/2017, I only want to pull up and display a message box containing '17'. How can I write this code in Macro using VBA in Excel?
1 Answer
Try this:
MsgBox Format(Date, "yy")
5 Comments
Olivia
Public Function ISOweeknum(ByVal v_Date As Date) As Integer ISOweeknum = DatePart("ww", v_Date - Weekday(v_Date, 2) + 4, 2, 2) End Function Private Sub CommandButton1_Click() Dim dt As Date Dim wno As Integer dt = Date Debug.Print dt wno = ISOweeknum(dt) MsgBox Format(dt, "yy") & wno End Sub
Olivia
This is the code I am trying on but the thing is today's week number is '3' and I want it to be displayed as 'W1703.4' How can I add a zero in front of the week number when it is single digit and also how that last digit '4' stands for Thursday and that last digit changes everyday like Monday is '1' and so on. So, how can write a code to pull this 'W1703.4'?
Fadi
MsgBox "W" & Format(dt, "yy") & Format(wno, "00.") & Weekday(dt, vbMonday)Olivia
Thank you so much!
A.S.H
@Pooja you never accepted any answer so far. Please when an answer solves your problem, think of accepting it by clicking the grey checkmark on the top-left of the answer, turning it into green.