There are a lot of combobox in sheet and they are appending dynamic. But all of combobox' assignments are same. They will run a function in macro. Can I rename all of combobox with same name? Or how can I do what I want?
Sub ekranadi()
Dim mainworkBook As Workbook
Set mainworkBook = ActiveWorkbook
For i = 1 To mainworkBook.Sheets.Count
If Left(mainworkBook.Sheets(i).Name, 5) = "Ekran"
Then ComboBoxEkranAdı.AddItem mainworkBook.Sheets(i).Name
End If
Next i
End Sub
If my understanding of your requirement is correct, the macro below will show you how to achieve the effect you seek.
A user form has a collection named
Controls
that contains every control on the form. Instead ofMyControl.Name
you can writeControls(6).Name
if 6 is the index number withinControls
ofMyControl
.The macro below outputs the index number, type name and name of every control on a form. If the control is a ComboBox, it adds three items to it with each item value being unique to the box.
Edit
Sorry I did not read your question carefully enough. I do not use controls on worksheets because I consider controls on user forms to be more powerful and more convenient. Controls on worksheets are further complicated by having two types: those loaded from the Controls toolbox and those loaded from the Forms toolbox. Functionality depends on which type you have.
To test the new macro
DemoWorksheet
, I loaded worksheet "Test" with both types of control. The macro shows how to fill both type of combo box via their collections.