VBA Option Buttons

ryancgarrett

Board Regular
Joined
Jun 18, 2011
Messages
122
I'm fairly new to VBA and have never used option buttons before, but I'm positive what I want to accomplish is possible. I have a form with a blank listbox and 5 option buttons. When the user opens the form and selects an option I want the listbox to populate based on the option button selected.

In short, how do I use option buttons to define the rowsource for a listbox?

Thanks for your help!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Code:
Private Sub OptionButton1_Click()
     ListBox1.RowSource = "Sheet1!A1:A10"
End Sub

Private Sub OptionButton2_Click()
     ListBox1.RowSource = "Sheet1!C1:C10"
End Sub

Private Sub OptionButton3_Click()
     ListBox1.RowSource = "Sheet1!E1:E10"
End Sub

Private Sub OptionButton4_Click()
     ListBox1.RowSource = "Sheet1!G1:G10"
End Sub

Private Sub OptionButton5_Click()
     ListBox1.RowSource = "Sheet1!I1:I10"
End Sub
 
Upvote 0
Hmmm that still isn't working. The theory sounds good, but it always gives me an error. I have tried the following:

optAsset.RowSource = "Chart of Accounts!B3:B17"
optAsset.RowSource = Sheets("Chart of Accounts").Range("B3:B17")
optAsset.RowSource = Sheets("Chart of Accounts").Range("B3:B17").Value

All of these have returned either a type mismatch error or a member not found error. Am I still doing something wrong?
 
Upvote 0
If the sheet name has spaces in it, you need to surround the name with single quotes...
Code:
optAsset.RowSource = "[COLOR="Red"]'[/COLOR]Chart of Accounts[COLOR="Red"]'[/COLOR]!B3:B17"
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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