+ Reply to Thread
Results 1 to 13 of 13

Problem with cell locking VBA code

  1. #1
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Problem with cell locking VBA code

    Hiya

    I've been playing around with a few bits of code, but am not that experianced in the art of VBA coding, but ill give everything a try.

    Having problems with the code listed below.

    The major bits of it work, but the three lines marked with " **->", i cant seemt o get to work, as i dont know what the protocol is.

    The code is suppose to lock the cells in all worksheets within a workbook, which works great, but there are two columns on seprate worksheets in the work book that i want to keep the cells unlocked and also a sheet that needs to be hidden.

    Please Login or Register  to view this content.
    As an after point, what i would like is to have an option window that appears before the worksheet is locked down so the user can select which worksheets to hide..

    G

    Oh and thanks to every one that has helped me so far, I cannot take any credit to the code above as its a mixture of many talents from this forum

    Cheers guys and Girls

    Last edited by drgogo; 03-02-2010 at 10:50 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Problem with cell locking VBA code

    At a first glance

    It appears you have not copied your code correctly, or you have only posted
    part of your sub.

    Try using
    Please Login or Register  to view this content.

    With without End With
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Remember Locked will have no effect unless you Protect the sheet

    Use the Debug>Compile VBA project to show any compile errors
    and
    Please Login or Register  to view this content.
    To avoid other errors
    Last edited by Marcol; 03-02-2010 at 06:34 AM.

  3. #3
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Problem with cell locking VBA code

    Correct, I have just noticed that the beginning and the end are missing, it should read as follows

    Please Login or Register  to view this content.
    But it always comes up with a error for this line

    Please Login or Register  to view this content.
    Every time i run the code I get a runtime error 438

    "Object doesn't support this property or method

    G

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Problem with cell locking VBA code

    Have a look again at Post #3 our posts crossed while I was editing

    Did not notice this one
    Please Login or Register  to view this content.
    spelling - visable should be visible
    Last edited by Marcol; 03-02-2010 at 06:38 AM.

  5. #5
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Unhappy Re: Problem with cell locking VBA code

    Thanks for that,

    But still the debugger wont get pass the Worksheets lines

    Please Login or Register  to view this content.
    This is producing a runtime error 438 as explained in my previous post

    ??



    G

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Problem with cell locking VBA code

    Posts Crossing again! See Post #4. Also seePost#2 again it is now updated to avoid clutter
    Last edited by Marcol; 03-02-2010 at 07:01 AM. Reason: Posts updated

  7. #7
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Problem with cell locking VBA code

    Ok, i had noticed that one as well, cant spell lol

    That work which is great, but now has stopped at teh following lines

    Please Login or Register  to view this content.
    Coming up with unable to lock the property

    Have tried many combinations, but still coming up with error

    Have i missed something or written it down wrong?

    G
    Last edited by drgogo; 03-02-2010 at 07:06 AM. Reason: Wrong error

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Problem with cell locking VBA code

    You must have the sheet protected.

    Please Login or Register  to view this content.
    And the same with the next line

  9. #9
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Problem with cell locking VBA code

    Thank works, but looking back at my original code, I have unprotected all worksheets and then protected them after i have locked the cells

    Please Login or Register  to view this content.

    and

    Please Login or Register  to view this content.
    So cant understand why i have to un protect them again ????

  10. #10
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Problem with cell locking VBA code

    Going back to my original code I have noticed that when i protect the worksheet it asks for a password which i set up, but after i use the lock code, when i go to unprotect, it does not ask for password to unprotect the sheet ??

    Forget this post, I missed out the password to re protect the sheet...
    Last edited by drgogo; 03-02-2010 at 07:58 AM. Reason: Sort out problem - Updated

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Problem with cell locking VBA code

    Okay I should have had a closer look at your code earlier

    You have used unprotect/protect but in that loop it will not work it is not sheet specific.
    Give me 10minutes or so and I will rewrite the whole lot and then edit this post by adding the revised code

    EDITED Promised revised code
    Please Login or Register  to view this content.

    1/. I have used for example Worksheets("Sheet1") ... etc - change each to suit your sheet names

    2/.also
    Password:="" Change this to your Password eg Password:="YourPassword"
    Both protect and unprotect passwords must match exactly
    The usual password rules case sensitive, illegal characters etc apply

    Try this and let me know how you get on
    Last edited by Marcol; 03-02-2010 at 09:44 AM. Reason: Solution added to avoid clutter

  12. #12
    Forum Contributor
    Join Date
    01-29-2008
    Location
    Scotland
    MS-Off Ver
    2003
    Posts
    237

    Re: Problem with cell locking VBA code

    Fantastic, works a treat,

    Big Thank you

    G

  13. #13
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Problem with cell locking VBA code

    Glad to have helped

    Regards
    Alistair

+ 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