VBA Excel Userform - Updating a Label

wageslave101

Board Regular
Joined
Jul 18, 2007
Messages
154
I am working with a userform that has;

OptionButton1, OptionButton2, OptionButton3
TextBox1, TextBox2
Label1

I'm trying to get the Label1.Caption to update, based on the OptionButtons being selected and details being added to the TextBox.

For example the user might select OptionButton2, Enter text into TextBox1 and TextBox2.

I'd like this to display "OptionButton2, Textbox1, Textbox2" in the Label1.Caption which will then be copied to a string to be pasted elsewhere.

I'm trying to get the Label1.Caption to update as the OptionButtons or Textboxes are changed so that it is evident before they commit the record to the spreadsheet.

Any thoughts?

Cheers,
Wageslave101
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try this. In the UserForm code put this:
Code:
Private Sub OptionButton1_Click()
CheckOptions
End Sub

Private Sub OptionButton2_Click()
CheckOptions
End Sub

Private Sub OptionButton3_Click()
CheckOptions
End Sub

Private Sub TextBox1_Change()
CheckOptions
End Sub

Private Sub TextBox2_Change()
CheckOptions
End Sub

Then in a standard module put this:
Code:
Sub CheckOptions()
Dim myString As String
myString = ""
With UserForm1
    If .TextBox1.Value <> "" Then myString = myString & "TextBox1 "
    If .TextBox2.Value <> "" Then myString = myString & "TextBox2 "
    If .OptionButton1 Then myString = myString & "OptionButton1 "
    If .OptionButton2 Then myString = myString & "OptionButton2 "
    If .OptionButton3 Then myString = myString & "OptionButton3 "
    .Label1.Caption = myString
End With
End Sub

Hope that helps!
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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