Consulting

Results 1 to 11 of 11

Thread: Hide or Unhide checkbox

  1. #1

    Hide or Unhide checkbox

    I have this code to hide or unhide a number of rows but am getting a "run-time error 1004, unable to set hidden property of the range class" I placed the checkbox into the spreadsheet using the control toolbox and placed the code into the code editor. My checkbox is named CheckBox1 and I cannot see any other reason for this error. Anyone have any idea how to fix it?
    [vba]
    Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
    ActiveSheet.Rows("3:15").EntireRow.Hidden = True
    Else:
    ActiveSheet.Rows("3:15").EntireRow.Hidden = False
    End If


    End Sub[/vba]

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Make sure that the worksheet in unprotected and also if you have any comments that are being hidden, check their properties and make sure they are set to Move and Resize with cells.

  3. #3
    I will do that now, thank you for your quick reply. In my sheet I have option boxes for a selection being made in column b and that result (true or false) goes into column a and tells another sheet that is doing a vlookupwhich answer to use. Would the option buttons be the cause for this?

  4. #4
    My worksheet is definitely unprotected and I did also have comments in some of those cells. I changed those to move and size with cells but I am still having the same trouble. Can I post it here for someone to look at?

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi TM,
    If you zip your workbook you can post it using Manage Attachments which you will find in the Go Advanced section
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Thank you, I will do that now.

  7. #7

    Hide or Unhide Checkbox

    Here's the workbook I am working with. Any help would be greatly appreciated.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The code works for me and if you change the Checkbox to 3, it should retain its position on the page. Sorry, I don't see any problems which result in the error message.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Is it possible that a setting in excel could cause this problem? Or is it possible that this code is not correct for Excel 97? I cannot figure this thing out and do not know where to turn. If it works well for others there would have to be something wrong within Excel on my end?

  10. #10
    I know this may seem a little far fetched, but would anyone within this forum lke to create a form that would do what my spreadsheet is doing and see if it make a difference? If not I will understand, I am just not hardly versed with userforms and have not grasped the full ability of the controls working with the spreadsheet to add and retrieve data from a userform.

  11. #11
    VBAX Newbie
    Joined
    Sep 2006
    Posts
    1
    Location
    Try removing the comments on the sheet you are having problems with. I was running into the same exact problem and your post about resizing the comments got me thinking. My sheet was erroring out, but then I remove the comments and now it worked. It may be worth a shot.

    Another possible solution instead of using comments would be to use data validation, and then the input message.

    Hope it works. Cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •