Reputation: 11
I am very new to VBA. I have two columns:
Column 1 a b c
Column 2 1 2 3
So in if I select a from the combo box - I wanted to text box to show 1.
I have been trying to figure it out through the other posts here but could not get it to work.
If you could explain it to me that would be great!
Private Sub UserForm_Initialize()
With Worksheets("Sheet1")
ComboBox1.List = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value
End With
End Sub
Thank you.
Upvotes: 1
Views: 781
Reputation: 23081
One way is to use VLOOKUP on the combobox value and put this code in the combo box change event so that it runs whenever it is changed. Or you could assign it to a button.
Amend control names as necessary.
Private Sub ComboBox1_Change()
Me.TextBox1.Value = Application.VLookup(Me.ComboBox1.Value, Worksheets("Sheet1").Range("A1").CurrentRegion, 2, 0)
End Sub
Upvotes: 1