get listindex value

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
The code below list the three years in a combo box. How can I get the value of listindex 3.

i.e. the code list 2020,2021,2022. I would like to get the value of 2022

VBA Code:
    With cboYear
        For iloop = Year(Date) - 1 To Year(Date) + 1 Step 1
            .AddItem iloop
        Next
    End With
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
You can use
VBA Code:
cboYear.Value
to get the selected value in the combo
 
Upvote 0
I think I'm not explaining myself....

when the userform is displayed, the combo box is populated. I would like to get the value (2022) without selecting the listindex. My goal is to check if the current year is not listed in the drop down, clear the combo box and re-populate the combo box with 2020, 2021, 2022, 2023
 
Upvote 0
In that case why not just run the code you posted when the userform initialises.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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