Fill TextBox from ComboBox Value

djossh

Board Regular
Joined
Jul 27, 2009
Messages
243
Hi I need to populate TextBox1 from ComboBox2... I need to get the value of ComboBox2 to appear in TextBox1 whatever the value of ComboBox2 is.. irregardless if it is Blank, Number, Text.. my point is whatever the value in ComboBox should fill the TextBox..

I have this code that auto populate Combobox2 & Textbox1 but there are times that i need to change the value of ComboBox2 ... and it will give me empty results on my TextBox..please help..

here is my current code:

Private Sub userform_initialize()
Dim x
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("CustAdd")
For Each r In .Range("A1", .Range("A65536").End(xlUp))
If Not IsEmpty(r) And Not dic.exists(r.Value) Then
dic.Add r.Value, Nothing
End If
Next
End With
x = dic.keys
Me.ComboBox1.List = x
End Sub



Private Sub ComboBox1_Change()
Me.ComboBox2.Clear: Me.ComboBox2.Clear
Set dic = CreateObject("Scripting.dictionary")
With Sheets("CustAdd")
For Each r In .Range("A1", .Range("A65536").End(xlUp))
If r = Me.ComboBox1.Value Then
If Not dic.exists(r.Offset(, 1).Value) Then
Me.ComboBox2.AddItem r.Offset(, 1)
dic.Add r.Offset(, 1).Value, Nothing
End If
End If
Next
End With
With Me.ComboBox2
If .ListCount = 1 Then .ListIndex = 0
End With
TextBox1.Text = ComboBox2.Column(1)
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,224,517
Messages
6,179,233
Members
452,898
Latest member
Capolavoro009

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