get previous month in cell

somenoob

Board Regular
Joined
Sep 19, 2011
Messages
100
Hi everyone, i have a question to ask

i need to set to be previous month of the current date in cell D16 on startup of the excel.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
2. For year in cell D15, if current month is Jan, then use previous year, else will use current year.

How do i code that out?
i have the following codes out now..

Sub ThisDate()
'display current month. eg Sep. For September, change to mmmm.
mth = UCase(Format(Date, "mmm"))
'Edit the position for the date to be displayed in the .Range("_") field.
Sheets("List").Range("D16").Value = mth
' display current year. eg FY2011.
yr = UCase(Format(Date, "yyyy"))
'Edit the position for the date to be displayed in the .Range("_") field.
Sheets("List").Range("D15").Value = "FY" + yr
End Sub

Thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You can do it simply with a formula:
=DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY()))

You could do the same in VBA using Application.WorksheetFunction most likely.
 
Upvote 0
is there a way to code it in vba. as the date might get changed by manually typing it to other dates. as now the previous month is aug. but i might manually type it to feb for eg.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,722
Members
452,939
Latest member
WCrawford

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