SOLVED

Populate userform combobox selection from a cell in a table

Copper Contributor

I created a userform (with VBA) to enter data into a sheet table. Works great but now I want to add the ability to view the records with the same userform. Essentially "reverse populate" the userform from the same table. I have added 'Prev' and 'Next' controls to scroll through records. My userfom has several textbox fields which I populate with TextBox1.Value = Sheets("Winter Roads Data").Range("C5") for example. However, my userform also has many comboboxes and I cannot figure out the correct code to populate a combobox "selection" (not the list) with table data. Is this even possible?? TIA

4 Replies
best response confirmed by GranSupt (Copper Contributor)
Solution

@GranSupt 

It is definitely possible to populate a ComboBox selection from a cell in a table using VBA. Here is how you can do it:

Let us assume you have a ComboBox named "ComboBox1" on your userform, and you want to populate its selection from a specific cell in your table. You can use the following VBA code to achieve this:

Vba Code

Private Sub UserForm_Initialize()
    ' Populate the ComboBox selection from a specific cell in the table
    Me.ComboBox1.Value = Sheets("Winter Roads Data").Range("C5").Value
End Sub

This code goes into the UserForm_Initialize event handler, which runs automatically when the userform is initialized or shown. It sets the value of the ComboBox to the value of cell C5 in the "Winter Roads Data" sheet.

You can adapt this code to populate other ComboBoxes on your userform by changing the ComboBox name and the cell reference accordingly.

If you want to populate the ComboBox with a range of values from a column in your table, you can use the RowSource property of the ComboBox. Here is an example:

Vba Code

Private Sub UserForm_Initialize()
    ' Populate the ComboBox selection from a range of values in a column in the table
    Me.ComboBox1.RowSource = "Winter Roads Data!C1:C10"  ' Change the range as needed
End Sub

This code sets the RowSource property of ComboBox1 to a range of values from column C in the "Winter Roads Data" sheet.

Remember to adjust the cell references and range as per your specific requirements and table structure. The text was created with the help of AI.

 

My answers are voluntary and without guarantee!

 

Hope this will help you.

 

Was the answer useful? Mark as best response and like it!

This will help all forum participants.

@GranSupt 

Try my file >> Mechanical Dryer Temperature Trend Report.xlsm - Microsoft Excel Online
Upon opening that file you will see button that will launch a Userform.
First you will need to select a date on the top of the form, so if the seleted date has no data in a table yet, it will appear like this:

Rr__0-1707983584138.png

 

but when the date already has a data on a table, it will retrieve all the data on their respective textboxes like this:

Rr__1-1707983717945.png

 

 

@Rr_ 

Unfortunately, I cannot directly access files or external content, including files hosted on external platforms. Therefore, I'm unable to view or analyze the file you've mentioned.

However, I can still provide guidance based on the description you've provided. If you're encountering issues with populating ComboBox selections from a cell in a table within your userform, you can use VBA to achieve this.

To populate a ComboBox with a specific value from a cell in a table, you can use VBA code similar to the following:

Vba Code

Private Sub UserForm_Initialize()
    ' Assuming ComboBox1 is the name of your ComboBox control
    ' Populate the ComboBox selection from a specific cell in the table
    Me.ComboBox1.Value = Sheets("YourSheetName").Range("A1").Value
End Sub

In this code:

  • Replace "ComboBox1" with the name of your ComboBox control.
  • Replace "YourSheetName" with the name of the worksheet where your table is located.
  • Replace "A1" with the cell reference from which you want to populate the ComboBox selection.

Make sure to place this code in the UserForm_Initialize event handler. This code will run when the userform is initialized, setting the value of the ComboBox to the value of the specified cell in the table.

Note: Microsoft Excel Online does not support VBA (Visual Basic for Applications), which means you cannot use VBA macros or code within Excel Online. Therefore, if you're working with Excel Online, you won't be able to use VBA to interact with userforms or implement custom form behaviors like you would in the desktop version of Excel.

However, you can still achieve certain functionalities using built-in features and formulas available in Excel Online. For example, you can use data validation to create dropdown lists in cells, or you can use Excel Online's filtering and sorting capabilities to interact with your data.

If you need more advanced functionality that's not available in Excel Online, you may need to switch to the desktop version of Excel. Keep in mind that any changes made in the desktop version may not be reflected in Excel Online unless you save and reload the file.

@NikolinoDE 
I think, it may require you to download the file. I guess...
but I'll attached the file here. it's a hefty file size since my button there was 3d model.. 

1 best response

Accepted Solutions
best response confirmed by GranSupt (Copper Contributor)
Solution

@GranSupt 

It is definitely possible to populate a ComboBox selection from a cell in a table using VBA. Here is how you can do it:

Let us assume you have a ComboBox named "ComboBox1" on your userform, and you want to populate its selection from a specific cell in your table. You can use the following VBA code to achieve this:

Vba Code

Private Sub UserForm_Initialize()
    ' Populate the ComboBox selection from a specific cell in the table
    Me.ComboBox1.Value = Sheets("Winter Roads Data").Range("C5").Value
End Sub

This code goes into the UserForm_Initialize event handler, which runs automatically when the userform is initialized or shown. It sets the value of the ComboBox to the value of cell C5 in the "Winter Roads Data" sheet.

You can adapt this code to populate other ComboBoxes on your userform by changing the ComboBox name and the cell reference accordingly.

If you want to populate the ComboBox with a range of values from a column in your table, you can use the RowSource property of the ComboBox. Here is an example:

Vba Code

Private Sub UserForm_Initialize()
    ' Populate the ComboBox selection from a range of values in a column in the table
    Me.ComboBox1.RowSource = "Winter Roads Data!C1:C10"  ' Change the range as needed
End Sub

This code sets the RowSource property of ComboBox1 to a range of values from column C in the "Winter Roads Data" sheet.

Remember to adjust the cell references and range as per your specific requirements and table structure. The text was created with the help of AI.

 

My answers are voluntary and without guarantee!

 

Hope this will help you.

 

Was the answer useful? Mark as best response and like it!

This will help all forum participants.

View solution in original post