how to get a label on a userform to show a specific date (a month) but with MINUS 1 year...

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
335
Office Version
  1. 2010
Platform
  1. Windows
What I am trying to make work is having labels that are located underneath these command buttons (which are on a userform) to show a specific MONTH and YEAR similar to what I have right now (and IS working) with how years are presented on some labels:

The code for the labels that show JUST the 'years' do work correctly (shown in the pic below) looks like this:
(so this is the code for the "2020" year that is circled:
Code:
Me.lbl2020b.Caption = Format(Now, "yyyy") - 1

(the "ALL" is a separate label and the caption says "(all")

So on the userform it appears like this:
Dates - Original.PNG

The labels for the months however, have me stumped.
Date - Aug 2021.PNG


I can't have the caption directly read "Aug 2021" because I need to userform to be current with whatever the actual date is whenever the userform is opened each time (the same way that the 'year' label works that I showed above.)

For the first month label for "Aug 2021", I need it to be something like:
Code:
="Aug "&TEXT(EDATE(TODAY(),-1),"yyyy")

(But that code doesn't work on a userform as it was copied from a formula on one of the worksheets. Also, "Aug" is static and I need it to say "Aug" based on the current month minus 1 month...)

Can someone please provide me with code that works with a LABEL on a userform that will show what the correct MONTH is based on whatever the current month is NOW minus 1 month? (the label would show "Aug 2020")
Thanks in advance for any help.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,043
Office Version
  1. 2019
Platform
  1. Windows
Hi,
try

VBA Code:
Me.Label1.Caption = Format(DateAdd("m", -1, Date), "mmm yyyy")

Dave
 
Solution
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,700
Messages
5,766,010
Members
425,322
Latest member
galaxy6623top

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
Top