VBA : Insert Date, Show Previous Date

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

VBA : Insert Date, Show Previous Date

Post by Susanto3311 »

hi all.
i have a code to insert date based on date in my pc system. the code work properly but I want to modified that code can work to be previous date like this:
if my pc system date in June 2022 after running code show May 2022,
if my PC system date Feb 2022 after running code show Jan 2022..etc...

Code: Select all

Sub Insert_Month()
Selection.InsertAfter Format(Date, "dddd, d MMMM YYYY")
End Sub
i try modified like this:

Code: Select all

Selection.InsertAfter Format(Date, "dddd, d MMMM YYYY")-[b]1[/b]
but not work..

anyone help, greatly appreciated..
susanto

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA : Insert Date, Show Previous Date

Post by HansV »

Try:

Code: Select all

Selection.InsertAfter Format(DateAdd("m",-1, Date), "dddd, d MMMM YYYY")
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA : Insert Date, Show Previous Date

Post by Susanto3311 »

ok Hans, thank you so much!! Worked it.