VBA: Input current YYYY-MM(+1) into a specific cell

larinda4

Board Regular
Joined
Nov 15, 2021
Messages
73
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I'm having a hard time trying to figure out a macro that will update the yyyy-mm(+1) in a specific cell. It needs to include the ' at the beginning as that year-month is used to update the table below it.

Example: It is currently September 2022 right now. I would need the macro to select cell C2, and update it to '2022-10

I found this code below that I was thinking maybe I could alter?

VBA Code:
Sub TestDate()
   Dim dtToday As String
   dtToday = Format (Date, "yyyy mm")
End Sub

Any help would be appreciated!
 
It really depends on what it is you are trying to do.
If this follows you original question, and you ALWAYS want the following month, then use the logic from the line of code I gave you originally, i.e.
Rich (BB code):
ActiveSheet.Name = Format(DateAdd("m", 1, Date), "yyyy mm") & "Final - By Region"
Thanks for taking the time to explain that to me. You've definitely saved me from potential errors in the future.

I wish I could buy you a coffee!
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You are welcome.
Glad I was able to help!

Yes, what you had originally would have worked for the rest of the month of September, but then when you hit October, it would returned "2022 Ocotber..." until October 16, at which point it would have switched over to "November 2022".
 
Upvote 0

Forum statistics

Threads
1,223,632
Messages
6,173,469
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top