VBA to select first item in a ComboBox

2Took

Board Regular
Joined
Jun 13, 2022
Messages
203
Office Version
  1. 365
Platform
  1. Windows
Trying to get VBA to select first item in a combobox. What do I need to add? Getting below error on this part at the end of code below:

Code:
:  Worksheet.ComboBox1.ListIndex = 0

2022-07-27_14h48_18.png


VBA Code:
If fixed_range.Row = n Or Not Intersect(ActiveCell, Range("B7")) Is Nothing Then MsgBox "That was a last step." & vbNewLine & "Back to step 1, for the next item in the Queue.", vbInformation, "Heads Up": Call ClearPBoard: Range("A11").Select: ActiveWindow.ScrollRow = ActiveCell.Row:  Worksheet.ComboBox1.ListIndex = 0: Exit Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I think the problem is "Worksheet"... it is not an object. You might have meant "Worksheets" (with the "s" on the end)... that is an object (a Collection), but you would need to specify what worksheet in it you were referring to. For example, if your ComboBox is on a worksheet named "Sheet1", then you code line should be...

Worksheets("Sheet1").ComboBox1.ListIndex = 0
 
Upvote 0
I think the problem is "Worksheet"... it is not an object. You might have meant "Worksheets" (with the "s" on the end)... that is an object (a Collection), but you would need to specify what worksheet in it you were referring to. For example, if your ComboBox is on a worksheet named "Sheet1", then you code line should be...

Worksheets("Sheet1").ComboBox1.ListIndex = 0
How do I do it by sheet code name? Better practice to do it that way, right?
 
Upvote 0
If you sheet's Code Name is Sheet1, just use it that way...

Sheet1.ComboBox1.ListIndex = 0
 
Upvote 0
Solution

Forum statistics

Threads
1,216,100
Messages
6,128,825
Members
449,470
Latest member
Subhash Chand

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