Selected Answer
Hi again Ali M
If you want the UserForm to show the months of the current year (e.g. JAN-24 to DEC-24), your code should be replaced by the following (changes in bold):
Private Sub UserForm_Activate()
Dim MyDate As Date
Dim i As Integer
' get January of this year
MyDate = DateValue("01/01/" & Year(Date))
For i = 1 To 12
' add months of this year
Me.ComboBox1.AddItem Format(MyDate, "mmm-yy")
MyDate = DateAdd("m", 1, MyDate)
Next
End Sub
The attached revised file has that code and works when you click the button.
If however you want to add the current month plus the next 11 months (e.g. Nov-24 to Oct-24) instead, just remove the minus sign (-) from the line within the loop in your code which updates MyDate (see changes in bold below):
Private Sub UserForm_Activate()
Dim MyDate As Date
Dim i As Integer
MyDate = Date
For i = 1 To 12
' add future months
Me.ComboBox1.AddItem Format(MyDate, "mmm-yy")
MyDate = DateAdd("m", 1, MyDate)
Next
End Sub
The above code is also in the attached file but is commented out (you'd need to uncomment it and delete the other code if this is what you want).
Hope one of these solutions fixes your problem. If so, please remember to mark this Answer as Selected.