Excel Combo box question

Robert C

New Member
Joined
Feb 18, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Excel Combo.JPG


I would like to add a button to my sheet that would set all selected values back to zero. These boxes are Combo Box's(Form Control).
I am using Office 365. Thank you for any assistance.
 

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)
Hi & welcome to MrExcel.
How about
VBA Code:
Sub RobertC()
   Dim Shp As Shape
   For Each Shp In ActiveSheet.Shapes
      Shp.ControlFormat.ListIndex = 1
   Next Shp
End Sub
 
Upvote 0
Thank you Fluff for your response. As I'm relatively new to Excel functions, would you be able to provide more detail re: the creation of the code? I'm assuming I need to insert a Button (Form Control) and somehow link it to the VBA code?
Thanks.
Robert
 
Upvote 0
The code needs to go in a standard module Insert and run VBA macros in Excel - step-by-step guide
Then if you insert a shape, or a form control button, onto the sheet, right click & assign macro.
Hello Fluff, I created the VBA macro and a Button (Form Control) and linked the button to my macro. I also saved the sheet as an .XLSM extension.
When I click the button, the Combo Box list fields do revert back to zero. Awesome! But...I get a Run-Time error 438. Object doesn't support this property or method.

Thank you.
Robert
 
Upvote 0
But...I get a Run-Time error 438. Object doesn't support this property or method.
I wasn't thinking, that's because of the button, try
VBA Code:
Sub RobertC()
   Dim Shp As Shape
   For Each Shp In ActiveSheet.Shapes
      If Shp.FormControlType = 2 Then Shp.ControlFormat.ListIndex = 1
   Next Shp
End Sub
 
Upvote 0
I wasn't thinking, that's because of the button, try
VBA Code:
Sub RobertC()
   Dim Shp As Shape
   For Each Shp In ActiveSheet.Shapes
      If Shp.FormControlType = 2 Then Shp.ControlFormat.ListIndex = 1
   Next Shp
End Sub
That works great! Thank you, Fluff. I will study up on the material that you provided.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,917
Messages
6,122,233
Members
449,075
Latest member
staticfluids

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