Combobox not populating - help

Dannyh1

Well-known Member
Joined
Nov 18, 2009
Messages
1,144
Hi,

I have the following code to populate comboboxes:

Code:
For i = 1 To 10
    With Sheets("Cats").Range("B2")
            While .Offset(k, 0) <> ""
                fill = .Offset(k, 0)
                With MISSES.Controls("C_" & i)
                    .AddItem fill
                    MsgBox fill
                End With
                k = k + 1
            Wend
        End With
Next i
        
MISSES.Show

For some reason my combobox will not populate

I have put the MsgBox in there temporarily to check there are items to add.

There are items there but when my userform comes up, there is nothing in the dropdown in the combobox

Thanks,
Danny.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Where is that code located and how are you running it?
 
Upvote 0
Hi,

It is in a Module.

When running in full script it will be called.

At the moment I have pulled it out to test & tried running just by View Macros - Run

Thanks
 
Upvote 0
Try putting the code in the userform's Initialize event.
Code:
Private Sub Userform_Initialize()
    For i = 1 To 10
        With Sheets("Cats").Range("B2")
            While .Offset(k, 0) <> ""
                fill = .Offset(k, 0)
                With MISSES.Controls("C_" & i)
                    .AddItem fill
                    MsgBox fill
                End With
                k = k + 1
            Wend
        End With
    Next i

End Sub
 
Upvote 0
Hi Norie,

I have just tried Initialize route but getting same issue!

Bit stumped.

Thanks,
Danny
 
Upvote 0
Can you post the code you tried?

Also, what's the range you are trying to populate the comboboxes with?
 
Upvote 0
This is the full code
Code:
Private Sub Userform_Initialize()


Dim i As Integer, dte As String, typ As String, des As String, amt As Double, fill As String


For i = 1 To 10
    MISSES.Controls("C_" & i).Clear
Next i


For i = 1 To 10
    k = 0
    With Sheets("Temp").Range("A2")
        If .Offset(i - 1, 0) <> "" Then
            dte = .Offset(i - 1, 0)
            typ = Format(.Offset(i - 1, 1), "0000")
            des = .Offset(i - 1, 2)
            amt = .Offset(i - 1, 3)
        Else
            dte = ""
            typ = ""
            des = ""
            amt = 0
        End If
    End With
    MISSES.Controls("D_" & i) = dte
    MISSES.Controls("T_" & i) = typ
    MISSES.Controls("DE_" & i) = des
    If amt <> 0 Then
        MISSES.Controls("A_" & i) = amt
    End If
    If amt > 0 Then
    [FONT=arial black]With Sheets("Cats").Range("A2")
            While .Offset(k, 0) <> ""
                fill = .Offset(k, 0)
                With MISSES.Controls("C_" & i)
                    .AddItem fill
                End With
                k = k + 1
            Wend
        End With
    Else
        With Sheets("Cats").Range("B2")
            While .Offset(k, 0) <> ""
                fill = .Offset(k, 0)
                With MISSES.Controls("C_" & i)
                    .AddItem fill
                    MsgBox fill
                End With
                k = k + 1
            Wend
        End With
    End If
    k = 0
    With Sheets("Cats").Range("C2")
        While .Offset(k, 0) <> ""
            nme = .Offset(k, 0)
            With MISSES.Controls("N_" & i)
                .AddItem fill
            End With
            k = k + 1
        Wend
    End With[/FONT]
Next i


End Sub

The parts not working are in bold.

The Lists are just Text items

Thanks
 
Last edited:
Upvote 0
Just realised I had not defined k, but this has not made a difference.

Thanks
 
Upvote 0
Have you tried stepping through the code with F8 to see if the section of code that's meant to populate the comboboxes is actually being executed?
 
Upvote 0
Hi,

I have just gone through with F8. All the rows in code are getting highlighted - still no dropdown options coming up!
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

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
Back
Top