4

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?

0

1 Answer 1

5

Try this:

MsgBox Format(Date, "yy")

Sign up to request clarification or add additional context in comments.

5 Comments

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
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'?
MsgBox "W" & Format(dt, "yy") & Format(wno, "00.") & Weekday(dt, vbMonday)
Thank you so much!
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.