Problems with ComboBox in a VB form

clasagu

New Member
Joined
Feb 3, 2006
Messages
11
Hi,
I made a Form in VB with 3 ComboBox. The Problem is that when I show the option list and select any alternative. After that when I open again the Button for show the alternatives, the list is repeated at the end of the original. In others words, How can I limited that??.......I wish a only list option in the ComboBox and in this time is gowing any time that i select an option for the list

Thanks for your help, and regards!!!!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
How exactly have you populated the comboboxes?
 

clasagu

New Member
Joined
Feb 3, 2006
Messages
11
View here.....the actual codes in a combobox

that it´s an example of the combobox codes right now......


Private Sub ComboBox1_Change()

'ComboBox1.Clear

ComboBox1.AddItem "PLASTICO"

ComboBox1.AddItem "MADERA"

ComboBox1.AddItem "METAL"

ComboBox1.AddItem "VIDRIO"

ComboBox1.AddItem "PAPEL"


End Sub


.....you can see something wrong????....sorry but I haven´t so much experience in Visual Basic.....thanks
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
Every time you make a selection in the combobox all those items will get added to it again.

If this is a userform then try using it's Initialize event.

Code:
Private Sub UserForm_Initialize()
'ComboBox1.Clear

ComboBox1.AddItem "PLASTICO"

ComboBox1.AddItem "MADERA"

ComboBox1.AddItem "METAL"

ComboBox1.AddItem "VIDRIO"

ComboBox1.AddItem "PAPEL" 
End Sub
Or uncomment this line.
Code:
'ComboBox1.Clear
 

clasagu

New Member
Joined
Feb 3, 2006
Messages
11

ADVERTISEMENT

Re:norie

Thanks for your help but if I use Initialize Event the selection options in the Combobox is empty!!!!
And if I erase the fisrt line(Combobox1.Clear) I don´t have any posibility for write another options that be not in the pre-determinated list.......
If you have any extra comments, send me.........
Regards
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
How exactly have you tried to use the Initialize event?
 

clasagu

New Member
Joined
Feb 3, 2006
Messages
11

ADVERTISEMENT

for Norie

I just copy the text sended for you.....

Private Sub UserForm_Initialize()
'ComboBox1.Clear

ComboBox1.AddItem "PLASTICO"

ComboBox1.AddItem "MADERA"

ComboBox1.AddItem "METAL"

ComboBox1.AddItem "VIDRIO"

ComboBox1.AddItem "PAPEL"
End Sub

In other words, I change the first line since
"Private Sub ComboBox1_Change()" to
"Private Sub ComboBox1_Initialize()".......

If your idea was different, explain me with details what need to do
One more time, thanks for your help.......
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
You should have copied the code exactly as I posted it.

And it should go in the userform's module.

A combobox doesn't have an Initialize event.
 

clasagu

New Member
Joined
Feb 3, 2006
Messages
11
Ok Norie, tanks for your help!!!
Finally I solved my problem with a office´s friend who help me this time......
Thanks for all and regards...
 

Forum statistics

Threads
1,136,431
Messages
5,675,806
Members
419,586
Latest member
RoteichA

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
Top