Update Textbox if Checkbox clicked

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I have a series of Checkboxes on a Userform and I need to update a Textbox if they are checked.

If the Checkbox is clicked true, I currently have a specific value added to a Textbox - but how do I remove that value if the user unchecks the box?

Purely as an example let's say the value is "Test"
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
in your userform module (checkbox1 and textbox1 are the names of my userform, you may need to change them)

Code:
Private Sub CheckBox1_Click()
    If Me.CheckBox1.Value Then
        Me.TextBox1.Value = "TEST"
    Else
        Me.TextBox1.Value = vbNullString
    End If
End Sub
 
Upvote 0
Thanks, and sorry, I should have explained better - if there is other text in the Textbox I need that to remain and only remove the value that is associated with the Checkbox.
 
Upvote 0
this then?

Code:
Const valToappend = [B]" Test"[/B]

Private Sub CheckBox1_Click()
    If Me.CheckBox1.Value Then
        Me.TextBox1.Value = Me.TextBox1.Value & valToappend
    Else
        Me.TextBox1.Value = Left(Me.TextBox1.Value, Len(Me.TextBox1.Value) - Len(valToappend))
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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