Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA String as Integer is always "zero"

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.

like image 677
MrDominikku Avatar asked Jul 18 '26 10:07

MrDominikku


1 Answers

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
like image 77
A.S.H Avatar answered Jul 21 '26 05:07

A.S.H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!