Add Numerical Tab Names in Combo box

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. 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.

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
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Do you currently have sheets called 2017,2018,2019 & 2020?
 
Upvote 0
In that case how can you combine the two codes?
What is that you are trying to do?
 
Upvote 0
after re reading my post, ur right. It's not possible. My mistake.
 
Upvote 0

Forum statistics

Threads
1,214,387
Messages
6,119,225
Members
448,877
Latest member
gb24

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