run time error'9':subscription out of range

khatri milan

New Member
Joined
Nov 6, 2019
Messages
17
i wanted to disable radio buttons through vba code using this code: Worksheets("Sheet4").OptionButtons("Option Button 18").Enabled = False

but when try to run it says "run time error'9' :subscription out of range". How can i make it work.

those radio buttons are in normal worksheet not in userform and the code is inside a subroutine.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
It should look something like this:

Change sheet name as option Button name to your needs:

Code:
Private Sub CommandButton1_Click()
'Modified  11/7/2019  12:27:47 AM  EST
Worksheets("Sheet2").OptionButton1.Enabled = False
End Sub

This assumes your using a Activex Option Button

Are you sure you want it Enable=False or
Value=False

Value changes if it is selected or not selected.
 
Upvote 0
@khatri milan, if it is a Forms Option button then your syntax is a valid syntax.
Run time error'9':subscript out of range is normally a naming error (either spelling or the correct number of spaces etc.) so you need to check if you have a sheet where the tab name is Sheet4? If yes do you have an OptionButton called Option Button 18 (including the correct spacing) on the sheet with the tab name Sheet4?

When asking questions involving buttons/controls then you really should state whether they are ActiveX or Forms controls as we are trying to guess here which you are using.
 
Upvote 0

Forum statistics

Threads
1,214,873
Messages
6,122,029
Members
449,061
Latest member
TheRealJoaquin

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