0

In order to fit my code, I needed to convert today's year to a two digit number (the last two digits). To test this, I tried:

Sub test()

Dim y As String

y = Format(Year(Now), "00")

MsgBox (y)
End Sub

I was told by a classmate that I could use the "Mid" function, but I'm not very familiar with VBA; any help?

1
  • Using format you use the letter that you want, so D for day, M for month and Y for year. The number of letters you use determines how it comes out. So YY will give you 21 whereas YYYY will give you 2021. Another example for a full date: "DD-MM-YY will give 24-01-21 whereas "DD-MMM-YYYY" will give 24-Jan-2021. Also instead of Year(Now), either use Date or Now() Commented Jan 23, 2021 at 22:51

2 Answers 2

2

Try:

y = Format(Date, "YY") 
Sign up to request clarification or add additional context in comments.

1 Comment

This is the answer.
1

Try this

Sub test()

Dim y As String

y = Right(Year(Now), 2)

MsgBox (y)
End Sub

Comments

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.