+ Reply to Thread
Results 1 to 19 of 19

initialize combobox

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    17

    initialize combobox

    Hi everyone,
    I have created a combobox on a worksheet (Sheet1). I would like to initialize with some values when the excel file opens. I use the following code:

    Private Sub Workbook_Open()
    Dim i As Integer
    
    Sheet1.ComboBox1.Clear
    
    For i = 1 To 4
    Sheet1.ComboBox1.AddItem i
    Next i
    End Sub
    in ThisWorkbook. But when I run the code I am getting error "Method or Data member not found", and ComboBox1 is highlighted. I really have ComboxBox1 in Sheet1.

    Please, I need your help
    Thanks in advance for your help.

    Joe

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: initialize combobox

    Welcome to the forum.

    ComboBox1 is an ActiveX control (i.e., from the Control Toolbox, not the Forms toolbar?)

    Does the worksheet named Sheet1 have the CodeName Sheet1?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    09-21-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: initialize combobox

    Thanks for your quick reply.
    ComboBox1 was created from Forms toolbar (Form Controls). Initially the name was "Drop Down 1" and I rename it to "ComboBox1"
    The worksheet named Sheet1 have the CodeName Sheet1.
    Thank you.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: initialize combobox

    That syntax is only valid for an ActiveX control.

    Why are you using a combo box instead of a data validation drop-down?

  5. #5
    Registered User
    Join Date
    09-21-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: initialize combobox

    I would like to create Combobox1 only once and setup in such a way that it appears in all cells of column A for exemple.
    Last edited by joe_for_good; 09-21-2010 at 08:40 PM.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: initialize combobox

    Forms combo boxes get their source from a range:
        With ActiveSheet.Shapes("Drop Down 1").ControlFormat
            .ListFillRange = "A1:A5"
            .LinkedCell = "B1"
            .DropDownLines = 5
        End With

  7. #7
    Registered User
    Join Date
    09-21-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: initialize combobox

    I would like to fill the combo box with some values not from a range(like "a","b","c"); those values will be loaded into the combo box when I open the sheet for the first time.
    Thanks

  8. #8
    Registered User
    Join Date
    09-21-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: initialize combobox

    I can initialize the drop down now with that code. Thank you. Now I would like to have the combox box appearing automatically in each cell of column B. Now I put it in B1. any idea?

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: initialize combobox

    I agree with Shg, why not just use Data Validation's List feature?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: initialize combobox

    Now I would like to have the combox box appearing automatically in each cell of column B.
    I'll leave that to someone else -- I think it would be an appallingly bad design.

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,299

    Re: initialize combobox

    Use Data Validation in column B, set the Allow option to List, and enter:
    a,b,c
    in the source box.
    Anyone who confuses correlation and causation ends up dead.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: initialize combobox

    The scale seems to be tilting definitively, Joe ...

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: initialize combobox

    That's what i thought you were suggesting earlier Shg

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: initialize combobox

    It was -- Romper just didn't read the whole thread, as I frequently don't.

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,299

    Re: initialize combobox

    I actually did (for once) - it just seemed that your suggestion had been ignored. I should have reiterated that it was your original suggestion but on that point I was being lazy!

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: initialize combobox

    I didn't feel slighted, and was happy to have you weigh in.

  17. #17
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: initialize combobox

    Some feedback from the OP would be good!

  18. #18
    Registered User
    Join Date
    09-21-2010
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: initialize combobox

    Thanks to all of you guys. Definitely, let's close the discussion with Data Validation List.

  19. #19
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: initialize combobox

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1