Av8tordude
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 1,075
- Office Version
- 2019
- Platform
- Windows
My workbook sheet tabs would be named by Year (i.e. 2018, 2019, etc). Currently I have one sheet (i.e. 2019). I would like to display in a combo box the previous 2yrs (i.e. 2018 & 2017) and also the following year (i.e. 2020). Maximum years displayed should be limited to 4. (i.e. 2017 - 2020) because the workbook will only have 4 worksheets.
This code adds the years to the combo box.
I have the code below that displays all sheets that are currently in the workbook (which works as expected).
If I would like to merge the two codes that will display the years as previously explained. if I have 4 worksheets then, then display the following year. (note: when the following sheet is added, the earliest sheet will be deleted). Is this possible.
Thank you kindly
This code adds the years to the combo box.
Code:
Dim ws As WorksheetDim iloop As Integer
With cboYear
For iloop = Year(Date) + 1 To Year(Date) - 2 Step -1
.AddItem iloop
Next
End With
I have the code below that displays all sheets that are currently in the workbook (which works as expected).
Code:
For Each ws In ActiveWorkbook.Sheets If ws.Visible <> xlSheetVeryHidden Then cboYear.AddItem ws.Name
Next
If I would like to merge the two codes that will display the years as previously explained. if I have 4 worksheets then, then display the following year. (note: when the following sheet is added, the earliest sheet will be deleted). Is this possible.
Thank you kindly