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
458
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi,
try

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

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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