Year code on useform to show current year & onwards only

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,219
Office Version
  1. 2007
Platform
  1. Windows
I am using the code below on my userform

When i open the userform for this month code i currently see 2023
If i then click the drop down arrow i then see,
2022
2023
2024
2025
2026

Please advise how i see 2023 when i open the userform BUT when i click the drop down arrow i then see the current year followed by years to come.
There is no need for me to see previous years thus,
2023
2024
2025
2026

Rich (BB code):
Private Sub UserForm_Initialize()
With Me
  With .cboYear
            .Clear
            'change the number to adjust years shown
            For i = -1 To 3
                .AddItem (Format(Date, "YYYY")) + i
            Next
            .ListIndex = 1
        End With
        With .cboMonth
            .Clear
            .List = Application.GetCustomListContents(4)
            .ListIndex = Month(Date) - 1
            L = .ListIndex
        End With
End With

loadDays

    Me.StartUpPosition = 0
    Me.Top = Application.Top + 300  ' MARGIN FROM TOP OF SCREEN
    Me.Left = Application.Left + Application.Width - Me.Width - 220 ' LEFT / RIGHT OF SCREEN


End Sub

I have tried to change a few values but unable to see what i require
Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi,

when running

Rich (BB code):
            For i = -1 To 3

you will catch the last year, you should try altering the code to read

Rich (BB code):
            'change the number to adjust years shown
            For i = 0 To 3
                .AddItem (Format(Date, "YYYY")) + i
            Next i
            .ListIndex = 0

Maybe adjust the upper limit of the counter to 4 if needed.

Ciao,
Holger
 
Upvote 0
Solution
That did the trick,i had changed only 1 value at a time but in this case needed to change two

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,405
Messages
6,119,320
Members
448,887
Latest member
AirOliver

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