Linking Userform Textbox with Userform Combobox Drop Down Value

PatHat

New Member
Joined
Oct 16, 2018
Messages
18
Hi Guys,

I would love some help here if you can.

I have a Userform that has a Textbox1 and a Combobox1, with a command button. The Combo Box drop down has a list of items and gets the data from a sheet somewhere else in the workbook.
What I'd like to happen is if the user selects the PERSONAL EFFECTS option from the combo box drop down list and clicks the command button, then Textbox1 on the same Userform gets filled in with text that says "Personal Effects (cover 20% of Contents Sum Insured)"

Here is my code. But when I click on the command button nothing happens on TextBox1. I'm new to VBA so forgive me if this is a silly post.

Private Sub CommandButton1_Click()
If Me.ComboBox1.Value = "PERSONAL EFFECTS" Then
Me.TextBox1.Value = "Personal Effects (cover 20% of Contents Sum Insured)"
End If
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Where do the original lists come from in the sheet, is there a named range etc. Its the lists on the sheet that is the issue not the coding.
 
Upvote 0
Its on a sheet called Lists which is hidden. I opened that up and removed the space at the end of personal Effects but still couldnt get it to work.
 
Upvote 0
In the code screen behind commadbutton one change the text to UPPER CASE as that is what it is looking for PERSONAL EFFECTS not Personal Effects, I just checked and it works.

VBA Code:
If Me.ComboBox1 = "PERSONAL EFFECTS" Then
 
Upvote 0
Oh Hooray!! you are my hero! And I initially had it in CAPS. Thanks again ever so much for all your patience on such a silly human error
 
Upvote 0
Problem is now it only works if the Personal Effects is selected.

I've tried adding this say that if the ComboBox is anything other than Personal Effects then Textbox must write what the user has manually put in the textbox field. But of course something is not right with my code.

ElseIf Me.ComboBox1 = "" Then
Me.TextBox1 = Me.TextBox1.Value
 
Upvote 0
Got it to work using this, not too worry

ElseIf Me.ComboBox1 = Me.ComboBox1.Value Then
Me.TextBox1 = Me.TextBox1.Value
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,040
Members
449,063
Latest member
ak94

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