Checkbox to input text to TextBox

harveya915

Board Regular
Joined
Sep 4, 2015
Messages
141
I have a UserForm with TextBoxes (1-4), kind of like answers to questions. Then I have a CommandButton that when clicked inputs the contents from the TextBoxes (1-4) to another TextBox (5) along with some other auto generated text.

I would like to add a checkbox to the UserForm that if checked will add a few more words to TextBox5.

This is the code I have:

VBA Code:
Private Sub UserForm1_Initialize()


TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""

End Sub

Private Sub CommandButton1_Click()
TextBox5.Value = "Random Text 1 in Text box 5" & TextBox1.Text & vbNewLine & "Random Text 2 in Text box 5" & TextBox2.Text & vbNewLine & "Random Text 3 in Text Box 5" & TextBox3.Text & vbNewLine & "Random Text 4 in Text Box 5" & TextBox4.Text
 
 
End Sub


Private Sub CommandButton3_Click()
Unload UserForm1
End Sub

I hope I did a good job explaining what I need, if not, please feel free to ask.

Much thanks for any help.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about something like this?

VBA Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
    TextBox5.Value = TextBox5.Value & "few more words"
End If
End Sub
 
Upvote 0
Solution
How about something like this?

VBA Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
    TextBox5.Value = TextBox5.Value & "few more words"
End If
End Sub
Thanks for the reply.

What if I need it to be run but once the CommandButton1 gets clicked. So if it is checked then I click the button it gives me a certain phrase. But if it's not checked and then I click the button then I get a separate phrase.
 
Upvote 0
I think I solved it (I'm completely new to this)

VBA Code:
Private Sub CommandButton1_Click()
If CheckBox1.Value = False Then
TextBox5.Value = TextBox1.Text & "Few More Words 1"
End If
If CheckBox1.Value = True Then
TextBox5.Value = TextBox1.Text & "Few More Words 2"
End If
End Sub

It seems to be working fine, but I would appreciate any feedback.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,678
Members
449,116
Latest member
HypnoFant

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