ComboBox / OptionButton code advice please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,

Below is an example of some code im surrently using to show / hide other optionButtuons

Rich (BB code):
    Private Sub OptionButton6_Change()
        If OptionButton6.Value = True Then
        OptionButton1.Visible = False
        OptionButton2.Visible = False
        OptionButton3.Visible = True
        OptionButton4.Visible = True
    Else
        TextBox3.Value = ""
        TextBox4.Value = ""
        End If
        End Sub


My question is how would i go about the same kind of thing BUT take the value from a ComboBox selection NOT an option button.

Example.
On my userform ComboBox1 has the selectable options ONE TWO THREE.

How would i write the code so that,

If ComboBox1.Value = "ONE" Then
OptionButton1.Visible = True

Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
you basically answered your own question
VBA Code:
    If ComboBox1.Value = "ONE" Then
        OptionButton1.Visible = True
    End If
you may need to make others not visible, which can be incorporated in the If block
 
Upvote 0
Strange as i did try that but nothing happened at all
 
Upvote 0
do you have it in a combobox_change event handler sub
 
Upvote 0
Yes
As it didnt do anything i was playing around with code like ComboBox.List or ComboBox.Index etc etc but i wasnt happy with what i was doing so asked here.
 
Upvote 0
try a doevents and see if that refreshes the userform view. or try checking combobox1.listindex value as a trigger
 
Upvote 0
Would you mind trying this your end as it looks ok but no option button is shown when i make the combobox selection
maybe you see an issue with what im using ?


Rich (BB code):
    Private Sub ComboBox1_Change()
        ComboBox1= UCase(ComboBox1)
        If ComboBox1.ListIndex = "ONE" Then
        OptionButton1.Visible = True
        End If
        End Sub
 
Upvote 0
this works for me

VBA Code:
Private Sub UserForm_Initialize()
    ComboBox1.AddItem "One"
    ComboBox1.AddItem "Two"
    ComboBox1.AddItem "Three"
End Sub

Private Sub ComboBox1_Change()
    If ComboBox1.ListIndex = 0 Then
        OptionButton1.Visible = True
    End If
    If ComboBox1.ListIndex = 1 Then
        OptionButton2.Visible = True
    End If
   
    'the general case is...
    'Controls("OptionButton" & ComboBox1.ListIndex + 1).Visible = True
End Sub
 
Upvote 0
combobox listindexes are numeric and start at 0, not 1 (ie Base Zero array)
 
Upvote 0
Thanks Post #8 worked so later i will work on the form.
If any issues i will reply here.

Have a nice day
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

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