Optionbutton link to listbox

Doflamingo

Board Regular
Joined
Apr 16, 2019
Messages
238
Hi all,

I have created a userform,

There are 2 conditions

The 1st condition with optionbutton1 and obtionbutton2 (they represent either ''Male'' or ''Female'')

The 2nd condition with optionbutton3, optionbutton4, optionbutton5 and optionbutton6 (they represent ''less than 18 years old", "between 18-30 years old", "between 30-50 years old" and the last one "more than 50 years old")

With those 2 conditions I would like to make appear in the listbox1:
if optionbutton1 and optionbutton3 are selected, the value in the listbox1 would be blank
if optionbutton1 and optionbutton4 are selected, the value in the listbox1 would be "ID"
if the optionbutton1 and optionbutton5 are selected the values in the listbox1 would be "ID" and below "Proof of Residence"...

Any ideas about how to link different optionbuttons to listbox ?:confused:

Here is the screenshot
https://www.dropbox.com/s/ltzai0gnsterb8v/Untitled.png?dl=0

Here is the beginning of the code

Code:
Private Sub UserForm_Initialize()
TextBox1.Value = ""
OptionButton1.Value = True
OptionButton2.Value = True
OptionButton3.Value = True
OptionButton4.Value = True
OptionButton5.Value = True
OptionButton6.Value = True
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Here is the code of the commamdbutton but it does not work :(

Code:
Private Sub CommandButton1_Click()
If OptionButton1 Is True And OptionButton3 Is True Then ListBox1.Value = ""
If OptionButton1 Is True And OptionButton4 Is True Then ListBox1.Value = "ID"
If OptionButton1 Is True And OptionButton5 Is True Then ListBox1.Value = "ID" & "Proof of Residence"


End Sub
 
Upvote 0
I've changed the code a little bit but still does not work ... :(

Any ideas ?

Code:
Private Sub CommandButton1_Click()
If OptionButton1.Value Is True And OptionButton3.Value Is True Then Me.ListBox1.AddItem ("")
If OptionButton1.Value Is True And OptionButton4.Value Is True Then Me.ListBox1.AddItem ("ID")
If OptionButton1.Value Is True And OptionButton5.Value Is True Then Me.ListBox1.AddItem ("ID" & "Proof of Residence")


End Sub
 
Upvote 0
The Is operator is used to compare two objects. Since you want to compare two values, use the Equality operator instead, for example...

Code:
[COLOR=#333333]If OptionButton1.Value = True[/COLOR]
 
Upvote 0
Hello @Domenic, thanks for your comment it works perfectly :)

Here is the code

Code:
If OptionButton1.Value = True And OptionButton3.Value = True Then Me.ListBox1.AddItem ("")
If OptionButton1.Value = True And OptionButton4.Value = True Then Me.ListBox1.AddItem ("ID")
If OptionButton1.Value = True And OptionButton5.Value = True Then Me.ListBox1.AddItem ("ID" & " " & "Proof of Residence")

But for the line

Code:
If OptionButton1.Value = True And OptionButton5.Value = True Then Me.ListBox1.AddItem ("ID" & " " & "Proof of Residence")

I would like to see in the list box ''ID'' and below ''Proof of Residence''' Currently the data are set in the same line, I would like to see them in different lines in the listbox1

Any ideas ?





****** id="cke_pastebin" style="position: absolute; top: 168px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">If OptionButton1.Value = True And OptionButton5.Value = True Then Me.ListBox1.AddItem ("ID" & " " & "Proof of Residence")
[/CODE]</body>
 
Upvote 0
Unfortunately, it looks like there's no setting that will allow an item to span multiple lines.
 
Upvote 0
Hi @Domenic,

I've found the answer and it works, maybe not the best way to write lines of code, but at least it works :)

Code:
If OptionButton1.Value = True And OptionButton5.Value = True Then Me.ListBox1.AddItem ("ID")
If OptionButton1.Value = True And OptionButton5.Value = True Then Me.ListBox1.AddItem ("Proof of Residence")
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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