VBA Code for name of previous month

wasimakram101 picture wasimakram101 · Apr 27, 2017 · Viewed 12k times · Source

I have added text in to my email that goes like:

"please provide numbers for MMMM month end" - where MMMM is the name of the previous month.

So it it's April today, MMMM will show March.

I have the following code:

Dim newDate: newDate = DateAdd("M", -1, Now)

But the result comes out to be 27/03/2017 16:37:58

I want it to show March.

Any suggestions?

Answer

Scott Craner picture Scott Craner · Apr 27, 2017

Format the return as "MMMM":

Dim newDate: newDate = Format(DateAdd("M", -1, Now), "MMMM")