VBA to add month and year to text

ROBINSON_US

New Member
Joined
Feb 27, 2006
Messages
25
I have this line of code, which adds a title to a report I've created:

ActiveCell.FormulaR1C1 = "ABC COMPANY INC. - SALES COMMISSION REPORT FOR JULY 2017"

Works great, but as each month goes by, I'd like to not have to go into the code and change the name of the month. Plus, when I do the reports, I'm in the next month (I'm doing July's reports in August, etc.) So, is there something that could look like:

ActiveCell.FormulaR1C1 = "ABC COMPANY INC. - SALES COMMISSION REPORT FOR " (plus code to add previous month's name)?

Thanks
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi, you could try:

Code:
ActiveCell.Value = "ABC COMPANY INC. - SALES COMMISSION REPORT FOR " & UCase(Format(DateAdd("m", -1, Date), "MMM YYYY"))
 
Upvote 0
Not sure why you are using .formulaR1C1 but the answer to your question is:

Code:
ActiveCell.FormulaR1C1 = "ABC COMPANY INC. - SALES COMMISSION REPORT FOR " & UCase(Format(DateAdd("m", -1, Now), "mmmm yyyy"))
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,588
Members
449,089
Latest member
Motoracer88

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