+ Reply to Thread
Results 1 to 3 of 3

Lock range of cells using VBA

  1. #1
    Registered User
    Join Date
    10-18-2011
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Lock range of cells using VBA

    I need help in this please.

    I have a sheet (sheet1) with a checkbox control that when it is checked unlook a range of cells in a different sheet (sheet2) and when I run this by checking the box I got a runtime error 1004: unable to set the locked property of the range class. The cells in the range in sheet 2 are protected and by checking the checkbox will be unprotected. Here is what I have:

    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 10-20-2011 at 01:45 PM. Reason: Code tags

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Lock range of cells using VBA

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    On this occasion I will change it for you but please remember in future.

    Try unprotecting the worksheet first with
    Please Login or Register  to view this content.
    and at the end of your macro switch sheet protection back on with Sheet2.Protect. I have assumed that sheet codename 'Sheet2' is the same as your tab name 'Sheet2'.

    You should get into the habit of using sheet code names rather than tab names which users may change. If they do your macro will not run.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    10-18-2011
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Lock range of cells using VBA

    Thank you very much, that works beautiful.
    Last edited by rtaboada; 10-20-2011 at 02:05 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1