Excel UserForm ComboBox/ListBox

pujo

Well-known Member
Joined
Feb 19, 2009
Messages
708
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
In an excel UserForm, I have 6 text boxes and a list box.
The listbox list is a table. When I open the userform and click on an item in the list box, the values are displayed in the text boxes on the userform.
This allows the user to edit the record.
VBA Code:
Private Sub ListBoxBillingAddress_Click()
    Me.txtbxBillingOffice.Value = Me.ListBoxBillingAddress.List(ListBoxBillingAddress.ListIndex, 0)
      Me.textboxCompany.Value = Me.ListBoxBillingAddress.List(ListBoxBillingAddress.ListIndex, 1)
        Me.textboxAddress.Value = Me.ListBoxBillingAddress.List(ListBoxBillingAddress.ListIndex, 2)
        Me.textboxCity.Value = Me.ListBoxBillingAddress.List(ListBoxBillingAddress.ListIndex, 3)
      Me.comboState.Value = Me.ListBoxBillingAddress.List(ListBoxBillingAddress.ListIndex, 4)
    Me.textboxZip.Value = Me.ListBoxBillingAddress.List(ListBoxBillingAddress.ListIndex, 5)
End Sub
I want to incorporate a combobox to do the same thing.

The combobox list is as followed:
VBA Code:
Me.cboSearch.List = ThisWorkbook.Worksheets("Billing").Range("tblBilling[Billing Office]").Value
When a "Billing Office" is selected, I want to populate the text boxes on the userfrom the same was as when I click on the list box item.
The user does not have access to the actual table, I am doing it all from a userform. When there is lots of entries in the table,
I think it would be easier to select the record to edit from a combobox rather than looking through all the listbox records.

I can't seem to figure out the syntax. Everything I have tried results in an error, could not et the list property...

All help is much appreciated!
 
@Fluff

So it was that easy....:oops:

Seeing the change, am I understanding that the "ListIndex + 2" makes the data range list start on row 2?
If not, would you please explain.

Cheers!
-PuJo
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
The listindex of a combo starts at 0, so when using a table you need to add 1 so that it looks at the 1st row, however when using a range you need to add 2 to get to row of the data, but if your data started at row 6, then you would need to add 6
 
Upvote 0
Solution
@Fluff
I understand (now)....:confused:
Thank you for your time.
Good Day!

-Pujo
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,749
Messages
6,126,661
Members
449,326
Latest member
asp123

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