help with a formula within a text box

Swifey

Active Member
Joined
Jan 16, 2003
Messages
421
For my text box on my form I have been shown the subsequent Default formula to calculate last months date – the screen view shows 200402

=IIf((Month(Date())-1)<9,Year(Date()) & "0" & Month(Date())-1,Year(Date()) & Month(Date())-1)

I would like to create a further text box on my form to calculate the prior months date. ie same month last year - screen view to show 200302

I have tried to modify the above formula but failed
Could you please help.

Kind regards
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Your formula returns a text answer not a numeric one which is probably why your other text boxes did not work.

=IIf((Month(Date())-1)<9,Year(Date())-1 & "0" & Month(Date())-1,Year(Date())-1 & Month(Date())-1)

Will return last year as text, if you wrap the formula's in the cLng function you will turn them back into numbers

=CLng(IIf((Month(Date())-1)<9,Year(Date())-1 & "0" & Month(Date())-1,Year(Date())-1 & Month(Date())-1))

HTH

Peter
 
Upvote 0
Or perhaps a neater function

=Format(DateAdd("m",-1,Date()),"yyyymm")-100

Peter
 
Upvote 0

Forum statistics

Threads
1,223,492
Messages
6,172,596
Members
452,466
Latest member
Lynlindsay

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