2

I have the following variable in my Macro:

todaydate = Year(Date) + Month(Date) + Day(Date)

How do I make the value of todayDate to be 20150415 instead of 2034?

2 Answers 2

2

To concatenate it as string, you need to use &.
Like this:

todaydate = Year(Date) & Month(Date) & Day(Date)

But this will yield: 2015415
To get what you want, try this:

todaydate = Format(Date, "yyyymmdd")

which will yield: 20150415

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

1 Comment

Thanks! That works! But I still want to learn how to concatenate variables in Macro. For example, now I would like to rename my active sheet based on a fixed string and the above todayData parameter. ActiveSheet.Name = PO_ + todayDate My expectation is the returned value should be "PO_20150415"
0
ActiveSheet.SaveAs Filename:= "PO_" & Format(Now(),"yyyymmdd") 

Hope this will help.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.