excel - VBA Macro and changing date format to mmm-yy -
i having problems excel macro (vba) meant grab date excel spreadsheet, subtract 1 month , reformat mmm-yy. want take 3/31/2013 , convert feb-13
here code:
dim reportdate date reportdate = worksheets("current").cells(2, 16) 'ex. 03-31-2013 prevmonth = format((month(reportdate) - 1) & "/" & day(reportdate) & "/" & year(reportdate), "mmm") & "-" & format(reportdate, "yy") debug.print prevmonth the result 2/31/2013-13
so tried changing prevmonth variable:
prevmonth = format((month(reportdate) - 1) & "/" & day(reportdate) & "/" & year(reportdate), "mmm-yy") but got 2/31/2013 again
i tried declare prevmonth integer or date type mismatch error. can declare string still doesn't program.
thanks in advance help.
try this
sub demo() dim reportdate date dim prevmonth date reportdate = worksheets("current").cells(2, 16) 'ex. 03-31-2013 prevmonth = dateadd("m", -1, reportdate) debug.print format(prevmonth, "mmm-yy") end sub
Comments
Post a Comment