Error: "Unable to Set Hidden Property Range" for Xls 2007 Users, FIX?

scherlerd

New Member
Joined
Sep 27, 2013
Messages
8
Hi All – </SPAN></SPAN>

I’m hoping you can help correct this problem. I have a large workbook that will be delivered to several hundred users and requires many data entry fields, meaning the workbook and each of its worksheets need to be protected. On one of the worksheets, users of Excel 2007 are running into the following run-time error: “Unable to set hidden property of the range class”. I need this to be fixed so that Excel 2007 & 2003 users won’t run into this problem.</SPAN></SPAN>

What: I have two form control option buttons (option button 30 & 31) that the user selects. Each button corresponds to a set of rows where the user is instructed to input additional information. The idea is that when one button is selected, only the rows of pertinent info displays and hides the rows that aren’t needed. More specifically, when option button 30 is selected, rows 41 through 48 should be hidden. When option button 31 is selected, rows 41 through 48 should be displayed.</SPAN></SPAN>

How: Here is the code I’m using. I wrote this on a PC using Excel 2010. The cell “X12” is the linked cell.</SPAN></SPAN>

Code:
</SPAN></SPAN>
Sub OptionButton30_Click()</SPAN></SPAN>
If Range("X12").Value = 1 Then</SPAN></SPAN>
Rows("41:48").Select</SPAN></SPAN>
Selection.EntireRow.Hidden = True</SPAN></SPAN>
Else</SPAN></SPAN>
Rows("41:48").Select</SPAN></SPAN>
Selection.EntireRow.Hidden = False</SPAN></SPAN>
End If</SPAN></SPAN>
Range("D16").Select</SPAN></SPAN>
End Sub</SPAN></SPAN>

Sub OptionButton31_Click()</SPAN></SPAN>
If Range("X12").Value = 2 Then</SPAN></SPAN>
Rows("41:48").Select</SPAN></SPAN>
Selection.EntireRow.Hidden = False</SPAN></SPAN>
Else</SPAN></SPAN>
Rows("41:48").Select</SPAN></SPAN>
Selection.EntireRow.Hidden = True</SPAN></SPAN>
End If</SPAN></SPAN>
Range("D16").Select</SPAN></SPAN>
End Sub</SPAN></SPAN>
[/endcode]</SPAN></SPAN>

Why: I want to make this usable for users of Excel 2007 and 2003, however users of 2007 are getting the run-time error: “Unable to set hidden property of the range class” as stated above. It works fine in 2010 and I can’t re-produce the error myself. </SPAN></SPAN>

I’m hoping this will be a simple solution for you excel gurus! Any ideas?!</SPAN></SPAN>

Thanks!</SPAN></SPAN>
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Thanks, Andrew!

No, they are form control Option Buttons. The excel code is on Sheet 2 under the MS Excel Object folder when I open up VBA. Does that answer your question?
 
Upvote 0
If the code is in the module for a worksheet they are ActiveX CommandButtons. This simplified version of your code works for me in Excel 2007:

Code:
Sub OptionButton30_Click()
    Rows("41:48").EntireRow.Hidden = OptionButton30.Value = True
End Sub

Sub OptionButton31_Click()
    Rows("41:48").EntireRow.Hidden = OptionButton31.Value = False
End Sub
 
Upvote 0
I see. I'm still learning vba and how to trouble shoot issues!

So I swapped in your simplified code and am now getting a "run time error 424: Object required". Did I read/input something wrong into vba? Or do I need to write a new macro with your code and re-assign it to my command buttons?

Thanks again for your help! :)
 
Upvote 0
Are you absolutely certain that your VBA code is in a Worksheet module? That can't be the case for an OptionButton from the Form Controls. Assigned macros must be in a General module like Module1.
 
Upvote 0
Okay. So I went back and looked, and these two codes are in Module14. Sorry for the confusion! Does that mean that these are actually ActiveX Controls (and likely the reason for the error for 2007 users)? Even though I inserted Option Buttons from the Form Control option?

If so, how do I replace them with Form Control buttons so that the code you sent above will work?
 
Upvote 0
In that case they are Form Control OptionButtons. Try:

Code:
Sub OptionButton30_Click()
    Rows("41:48").EntireRow.Hidden = ActiveSheet.OptionButtons(Application.Caller).Value = xlOn
End Sub

Sub OptionButton31_Click()
    Rows("41:48").EntireRow.Hidden = ActiveSheet.OptionButtons(Application.Caller).Value = xlOff
End Sub

which works for me in Excel 2007.
 
Upvote 0
Hazzah! It worked! Thanks so much for your due diligence and speedy help! I'm not quite sure what your code is telling excel to do/why this is solution works and mine didn't but happy to know that it does. If you get a second and wouldn't mind offering a quick explanation that would be helpful to learn for the future. If youdon't have the time, I understand!

Thanks again!!
 
Upvote 0
Hi Andrew - sorry to have another ask. But do you know a quick way to use the same command buttons to achieve the same affect on another sheet? So when the user clicks Option Button 31, it hides active rows 41:48 AND rows on another Worksheet different from the active one? I've tried a bunch of different options but keep getting a "object required" error message. Thought you might know a simple solution!

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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