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
 

PatHat

New Member
Joined
Oct 16, 2018
Messages
18
Awesome, thanks so much!! Cant believe it was sooo simple. I feel silly :)
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

PatHat

New Member
Joined
Oct 16, 2018
Messages
18
I dont know the Len function yet and how to use it. I'll have to read up
 

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,692
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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.
 

PatHat

New Member
Joined
Oct 16, 2018
Messages
18
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.
 

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,692
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

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
 

PatHat

New Member
Joined
Oct 16, 2018
Messages
18
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
 

PatHat

New Member
Joined
Oct 16, 2018
Messages
18
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
 

PatHat

New Member
Joined
Oct 16, 2018
Messages
18
Got it to work using this, not too worry

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

Watch MrExcel Video

Forum statistics

Threads
1,119,099
Messages
5,576,128
Members
412,698
Latest member
Lilly13m
Top