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.
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
Where is that code located and how are you running it?
 

Dannyh1

Well-known Member
Joined
Nov 18, 2009
Messages
1,144
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
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
 

Dannyh1

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

ADVERTISEMENT

Hi Norie,

I have just tried Initialize route but getting same issue!

Bit stumped.

Thanks,
Danny
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
Can you post the code you tried?

Also, what's the range you are trying to populate the comboboxes with?
 

Dannyh1

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

ADVERTISEMENT

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:

Dannyh1

Well-known Member
Joined
Nov 18, 2009
Messages
1,144
Just realised I had not defined k, but this has not made a difference.

Thanks
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,216
Office Version
  1. 365
Platform
  1. Windows
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?
 

Dannyh1

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

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

Watch MrExcel Video

Forum statistics

Threads
1,122,334
Messages
5,595,567
Members
413,996
Latest member
mabelO

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