0

I am having issues getting my combo boxes to populate. I have used: How to add items to a combobox in a form in excel VBA?

I have also made sure that my lists are named on that worksheet. What am I doing wrong?

Here is the code for the initialization

Private Sub UserForm1_Initialize()
    'Import Combo Box Lists
    Dim cCart As Range
    Dim cLoc As Range
    Dim wsz As Worksheet
    Set wsz = Worksheets("Stockout Reference")

    For Each cLoc In wsz.Range("Location")
        With Me.Location
            .AddItem cLoc.Value
        End With
    Next cLoc

    For Each cCart In wsz.Range("CartName")
        With Me.Cart
            .AddItem cCart.Value
        End With
    Next cCart

    Me.txtDate1.Value = Format(Date, "Medium Date")
End Sub  

I do have code for the userform that follows this, but none of the variables are the same so I don't see how that could be an issue.

Community
  • 1
  • 1
Jester799
  • 3
  • 1
  • 5
  • What is .Range("Location")? Is it a custom column or Row name taht you created? – danieltakeshi Sep 21 '17 at 12:16
  • Location is the column name in the data reference. It is also the name of the combo box. Could that be the issue? – Jester799 Sep 21 '17 at 12:49
  • Yeah, but what is the column name? Is it "A","B","C" or did you change it to a custom name "Location"? – danieltakeshi Sep 21 '17 at 13:02
  • I changed it to custom name "Location" same with "CartName". Name manager references: CartName refers to 'Stockout Reference'!$C:$C, Location refers to "Stockout Reference'!$A:$A – Jester799 Sep 21 '17 at 13:09
  • Well, i think your range is too big. Is it giving some error or just taking a long time to load? You could get the last line `lastrowA=wsz.Cells(wsz.Rows.Count, "A").End(xlUp).Row` and populate with: `For each cell in Range("A1:A"&lastrowA): If cell <> "" Then Location.AddItem cell.Text: Next cell` assuming it starts on row 1 – danieltakeshi Sep 21 '17 at 13:28
  • No error code, and no loading at all. I will try that and let you know. – Jester799 Sep 21 '17 at 13:43
  • Didn't work. I rewrote my code in a new workbook and the lists are loading fine. I'm still not sure what caused this error though. Thanks for the assistance anyway. – Jester799 Sep 21 '17 at 19:48

0 Answers0