Excel VBA Combobox Populate

  • I just can't seem to figure this out. Seems so simple yet it won't populate. I have to comboboxes on a userform. The userform is named frmReportMaker. The two comboboxes are called cboIssueSelect and cboMonthSelect. Here is the code I've written to populate these 2 comboboxes but it will not load when the form is loaded.


  • Re: Excel VBA Combobox Populate


    Davesexcel, yes I did try without the brackets. I also tried me.cboIssueSelect as well. It just makes so since to me. I've done comboboxes like this several times and have never had this issue. I know that the code does see the combobox because as soon as I hit the period under the with statement, the options comes up to use whatever I want. I even tried to populate it based on a range in the spreadsheet as well and it still didn't work. I like that code too by the way. May change the month population once this is figured out.

  • Re: Excel VBA Combobox Populate


    In doing some further research on this, I found a lot some saying that the initialize event doesn't use the form name and instead should be using UserForm_Initialize(). I gave that a try and get an error saying "Ambiguous name detected: UserForm_Initialize". I just don't get this. I think the issue with the population is within the initialize event but maybe I'm wrong. This is a crucial part to what I'm trying to create. Without it, this workbook is almost worthless.

  • Re: Excel VBA Combobox Populate


    The correct procedure name is 'UserForm_Initialize'


    The stub for this procedure is usually added by VBA. If you go view the code window for the userform, select 'UserForm' from the dropdown top left of the window and then 'Initialize' from the dropdown top right, then the Event code (if any exists) will be shown. If there is no code, VBA will add the procedure declaration followed by an 'End Sub'


    "Ambiguous name detected" means you have 2 Userform_Initialize procedures. One is probably blank, so remove it, or do whatever so there is only one.

  • Re: Excel VBA Combobox Populate


    I'm also very a 'Newbie' to Excel VBA and I'm having all sorts of problems, particularly with populating multiple comboboxes on the same 'UserForm'.


    My 'UserForm' contains 2 comboboxes - cbIdentS and cbCalRun


    Can anyone tell me why this code doesn't work? It throws up a 'Compile Error: Method or data member not found'.


    Private Sub UserForm_Initialize()
    Dim cell As Range
    Dim Rng As Range

    With cbCalRun
    ThisWorkbook.Sheet3 ("Calibration")
    Set Rng = .Range("A2", .Range("A2").End(xlDown))
    End With
    For Each cell In Rng.Cells
    Me.cbCalRun.AddItem cell.Value
    Next cell

    With cbIdentS
    ThisWorkbook.Sheet1 ("Scope_of_Work")
    Set Rng = .Range("B2", .Range("B2").End(xlDown))
    End With
    For Each cell In Rng.Cells
    Me.cbIdentS.AddItem cell.Value
    Next cell
    End Sub


    Any help would be much appreciated.


    Niknek

  • Re: Excel VBA Combobox Populate


    Welcome to OzGrid, Niknek.


    The policy here is you do not post questions in other members' threads, even if your query is similar, or related to, the topic discussed in the thread.


    Please start your own thread, give it an accurate and concise title that describes your issue and explain your problem fully,


    Also, when you post code in a message, you are asked to use Code tags. These format and indent the code making it easier to read and follow the logic. Code tags are added when editing ameesage - just highlight the code and click the '#' button on the toolbar above the edit box.

  • Re: Excel VBA Combobox Populate



    Sorry Cytop,


    It just shows what a 'Newbie' I am.

  • Re: Excel VBA Combobox Populate


    Try


    Code
    With Me.cboMonthSelect
                .Clear
                .List = Application.GetCustomListContents(4)
    ''///select current month
                .ListIndex = Month(Date) - 1
              
            End With

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!