2

I'm creating a macro which will recognize months and put first 3 letters and 2 last numbers of the year into sheet name. This is what I have created so far:

For example Cells(9,1) is first day of the month (01/01/2016)

Dim mName(13) As Integer
Dim ValDate As String
Dim years As String
Dim mcount As String

mName(1) = January
mName(2) = Febuary

...

mName(13) = December

years = Right(Year(Cells(9, 1)), 2)   '16
ValDate = mName(Month(Cells(9, 1)))   'macro says its 0, but it should be January)

mcount = Left(ValDate, 3) 

Sheets(Sheets.Count).Name = ValDate & " " & years

Result of the macro is "0 16" My goal is "Jan 16".

Macro works fine (no errors) but its always shows "0" when there is mName integer in ValDate string. Month function works fine with no mName.

0

2 Answers 2

6

Enclose the names with double-quotes.

Dim mName(1 To 12) As String

mName(1) = "January" '<~~~ double quotes
...
mName(12) = "December" '<~~~ 12, not 13. There are only 12 months in a year
Sign up to request clarification or add additional context in comments.

1 Comment

month 13 is undecimember :)
4

VBA considers January as a Variant. You have not initialized January so its value is 0

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.