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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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