Forum Discussion
Combo Boxes not displaying Data
guitar713 The error message you're getting is a pretty good indication that "Table3" does not exist as a defined name in the workbook. To verify the name of the table you want to use as the RowSource, select any cell within the table, then go to the Table Design tab on the ribbon. Copy the Table Name and paste it into your code to ensure that it's spelled correctly.
- djclementsMar 05, 2024Bronze Contributor
guitar713 Just as one last troubleshooting step, are you able to open the second userform on its own? From the Visual Basic editor, if you double click on the userform name in the project pane to view it, then press F5 on your keyboard, does it open up with the combobox populated? At this point, without working on your file directly, I'm out of ideas.
- guitar713Mar 05, 2024Brass ContributorYES, THAT WORKS.....
- djclementsMar 05, 2024Bronze Contributor
guitar713 So that begs the question... how exactly did you "link" the userform/combobox to the worksheet? In your original post, you stated the following:
"Yes, the second form is linked to the excel sheet just as the first form is. Followed same procedure as the first form box."
Please describe the procedure you followed. I'm confused, because after trying my suggestions, you then stated:
"I have tried to fill in the "RowSource" property as well in the properties dialog... That did not work either..."
The RowSource property is the only way that I'm aware of to "link" a combobox to a range in the workbook. If you didn't set the RowSource, and you're not populating the combobox via a loop, then what procedure did you use?
To populate a combobox via looping through the column of an Excel table, the code would look something like this:
Private Sub UserForm_Initialize() Dim tbl As ListObject, i As Long Set tbl = Sheet1.ListObjects("Table3") For i = 1 To tbl.ListRows.Count Me.ComboBox1.AddItem tbl.DataBodyRange(i, 1).Value Next i End Sub
Note: Sheet1 is the CodeName of the worksheet where the table resides, and the column number used in this example is 1. Adjust as necessary.
You may also take a look at the sample file I've been testing these procedures with and compare the setup with yours to see if anything jumps out (see attached).