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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
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!
 

Forum statistics

Threads
1,181,102
Messages
5,928,063
Members
436,586
Latest member
latintxn

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
Top