macro to insert dates from previous month

Will17

New Member
Joined
Apr 27, 2011
Messages
5
Dates will be the same each month, 5, 6, and 20. instead of manually entering the dates each month.. I wanted a macro to enter these dates. Ie, its now May, I need 4/6/2011, 4/5/2011, and 4/20/2011.. next month ill need 05/05/2011, etc. I think I can do the rest of the macro myself, just didn't have any luck searching for this.

Editing to add that these dates should just go in cells m1:m3.
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Have a look at this:
Code:
[FONT=Courier New][SIZE=2][COLOR=Navy]Option Explicit[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=Navy]Private Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]UpdateDates()
    Range("M1").Value = DateSerial(Year(Now), Month(Now), 5)
    Range("M2").Value = DateSerial(Year(Now), Month(Now), 6)
    Range("M3").Value = DateSerial(Year(Now), Month(Now), 20)
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=Navy]End Sub[/COLOR][/SIZE][/FONT]

Regards,

JuanPa
 
Upvote 0
Have a look at this:
Code:
[FONT=Courier New][SIZE=2][COLOR=Navy]Option Explicit[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=Navy]Private Sub [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]UpdateDates()
    Range("M1").Value = DateSerial(Year(Now), Month(Now), 5)
    Range("M2").Value = DateSerial(Year(Now), Month(Now), 6)
    Range("M3").Value = DateSerial(Year(Now), Month(Now), 20)
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=Navy]End Sub[/COLOR][/SIZE][/FONT]

Regards,

JuanPa

Cool thanks. I just added a -1 to month(now) and it works the way I want. Only concern is in January and the date I need is previous year.

Actually... just tested. It works then too.
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

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