• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Compile Error - ComboBox

enowapi

New Member
Hello,


I am trying to write a simple add item query to a combo box. Below is my code:


With Sheet1.ComboBox1

.AddItem "Paris"


But I keep getting a Compile error: Method or data member not found.


I suspect it's something wrong with the ComboBox1 "code function". Usually when I start typing the code Sheet1. then a list of all availabile "functions" will pop up in a list, but when I type ComboBox1, this "function" is not available through the list.


Does anyone know why? Thank you for your help.


Enowapi
 
Spelling and capitalization correct? Everything looks good when I run it on my machine. Did you rename the combo box possibly?
 
1. If you have insert the ComboBox in Sheet1 .. from Developer > Controls > Insert > Form Control > ComboBox.. then, Right Click on the ComboBox and check the NameBox.. It may be Drop Down 1, not ComboBox1. and you can't use it in your Macro..

Try... Right Click > Format Control > Control > Input Range > A5:A9 (or the location where "Paris","London"... are written)


2. If you have insert the ComboBox in Sheet1 .. from Developer > Controls > Insert > ActiveX Control
> ComboBox..
, then, your Code will Work perfectly..
 
I tried right clicking on the combo box, but I cannot find the NameBox?


I only see "Cut, Copy, Past, Group, Order, Assign Macro, Format Control". Can you point me to the right direction?
 
ahh..I see where the NameBox is and it is "Drop Down 1". When I try to replace ComboBox1 with Sheet1."Drop Down 1", I see get the same error.


I have tried using:

1. Sheet1.Drop Down 1

2. Sheet1."Drop Down 1"


Both still get the same compile error. Do you know why?
 
Name Box is in left Side of the Formula Bar, at the top of the sheet, below ribbon..


I says Right Click, because, If you are not in Design Mode , you will not able to view the Name of the Control..


As I can see, "Assign Macro" Button on Right Click, So you need to confirm, that it is a "Form Control".. You cant use any Form Control in coding.. You can only Right Click > Format Control > Control > Input Range > A5:A9 (or the location where "Paris","London"... are written)


Try to add the Combo Box from Developer > Controls > Insert > ActiveX Control > ComboBox.. From the bottom part of Insert Menu.. Now you can able to use the code ..

Code:
Sheet1.ComboBox1.AddItem "Paris"


Regards,

Deb
 
Back
Top