Excel 2013 - Form Controls in VBA

Rocky0201

Active Member
Joined
Aug 20, 2009
Messages
278
Hi,

Is it possible to create a ComboBox (Form Controls) on my active sheet in VBA code? Specifically, adding a ComboBox and then setting the ComboBox to point to a sheet and the list in the sheet to display the dropdown in the ComboBox.

Example:

Sheet1 is where I would add a ComboBox (width, height and position on sheet1).

Sheet2 is my list of Values in column A, Rows 1 through x

Point to Sheet2's list in the ComboBox that I added in Sheet1

In advance, thanks for your help.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I found a means to add a Combo Box to my sheet.

Set wsSheet1 = ThisWorkbook.Worksheets("Converter")
With wsSheet1.Shapes.AddFormControl(xlDropDown, _
Left:=150, Top:=30, Width:=200, Height:=20)
.ControlFormat.DropDownLines = 10
End With

My question is--- If I were to do "other" things in my code and then wish to come back to this drop down, how can I determine the name of the drop down so that I can add items to the drop down list?

Thanks
 
Upvote 0
I found a means to add a Combo Box to my sheet.

Set wsSheet1 = ThisWorkbook.Worksheets("Converter")
With wsSheet1.Shapes.AddFormControl(xlDropDown, _
Left:=150, Top:=30, Width:=200, Height:=20)
.ControlFormat.DropDownLines = 10
End With

My question is--- If I were to do "other" things in my code and then wish to come back to this drop down, how can I determine the name of the drop down so that I can add items to the drop down list?

Thanks

The first time you add it in code it is called "Drop Down 1", you can reference that in the code immediately after it was created and update the name:

wssheet1.Shapes("Drop Down 1").Name = "MyCMB"

Is the state of the workbook destroyed on close ...? Will you recreate the combobox in code again....?
 
Upvote 0
Thank you Kevin for getting back to me.

When the workbook is closed, I will not preserve any combo box's that I create.

My design is to create a combo box and then update the box with drop down data. Once the user selects from the drop down data, I will then create another combo box with additional drop down data based off of the user selection.

My project:

When the user opens my Converter workbook, they have a button on the Converter Sheet which, when pressed, an Open File Dialog box appears. The user then selects which Excel Workbook they wish to open.

I then extrapolate all of the sheets in the workbook and, when I get the code running, will create a drop down list with the sheet names.

The user will then select which sheet in the opened workbook to process.

Once the user makes this selection, I will build another drop down with the column headers (row 1).

The user will then select which column that needs to be converted.

I will then perform the conversion, write the data back out to their workbook, save an close their workbook.

Hope this makes sense.

Thanks again Kevin.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
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