Using an Index formula to populate a TextBox on a Form

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,342
Office Version
  1. 365
Platform
  1. Windows
I have a ComboBox (Combo1) that after a selection is made I want to populate other Textboxes using an Index formula

The names are"
ComboBox = ComboBox1
The Tab where my table is = BuyerID or Sheet10
The table field that I want to pull the data from = Buyer
The Match from selection in ComboBox
Match Field "BuyerID" (Yes, its the same name as the tab)

Code:
Private Sub ComboBox1_Change()



TextBox1 = Sheet10.Range("C18").Value

TextBox2 = WorksheetFunction.Index(Range("BuyerID[Buyer]"), WorksheetFunction.Match(ComboBox1, Range("BuyerID[BuyerID]"), 0))

End Sub

not sure what's wrong with the index formula but its not working
Thanks
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Range("BuyerID[Buyer]") ==> Sheets("BuyerID").[Buyer]
 
Upvote 0
Still getting an error
Code:
Private Sub ComboBox1_Change()

TextBox2 = WorksheetFunction.Index(Sheets("BuyerID").[Buyer], WorksheetFunction.Match(ComboBox1, Sheets("BuyerID").[BuyerID], 0))

End Sub

Run-time error '1004':
Unable to get the Match property of the worksheetfunction class
 
Upvote 0
How are you populating the combobox?
 
Upvote 0
Put under you code:

Debug.Print [Buyer].Address
Debug.Print [BuyerID].Address
Debug.Print ComboBox1

Open the View: Window Direct
Run your macro
 
Upvote 0
How are you populating the combobox?
Norie Im not sure I follow your question. The combobox is on a userform. The User scrolls to the item they want and then clicks on it.
 
Upvote 0
How is the combo getting it's list of values?
 
Upvote 0
I am using the RowSource properties

RowSource =BuyerID!A2:F5000
BoundColumn 1 (Which is the BuyerID)
ListRows 8
 
Upvote 0
Ok, how about
VBA Code:
Private Sub ComboBox1_Click()
   Me.TextBox2 = Range("Buyerid[Buyer]").Cells(Me.ComboBox1.ListIndex + 1, 1)
End Sub
 
Upvote 0
Solution
Thank you.

For future reference: I was using the Worksheet name when I should have been using the table name.

This worked

Me.TextBox1 = Range("ModelGeneral_vluBuyer[BuyerID]").Cells(Me.ComboBox1.ListIndex + 1, 1)
Me.TextBox2 = Range("ModelGeneral_vluBuyer[Buyer]").Cells(Me.ComboBox1.ListIndex + 1, 1)

Thank you all
 
Upvote 0

Forum statistics

Threads
1,215,464
Messages
6,124,969
Members
449,200
Latest member
Jamil ahmed

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