+ Reply to Thread
Results 1 to 5 of 5

VBA code not working when I protect the sheet

  1. #1
    Forum Contributor
    Join Date
    09-04-2007
    Posts
    127

    VBA code not working when I protect the sheet

    Good morning to all!!!

    I have used the below code to make hide/unhide some columns in my excel sheet. It works fine. Now, I need to protrect the sheet except the coloured cells. So I unlocked the cell by clicking the property of the colored cells & then did this :- tools- protection-Protect sheet - protect unlocked cells.

    But after protecting this sheet the macro code of hiding/unhiding of the columns are NOT WORKING & Errors is coming. I have used the below code:-
    Please Login or Register  to view this content.
    CAN ANYBODY HELP ME please.

    I have attached a jpeg of my excel sheet.
    Attached Images Attached Images
    Last edited by VBA Noob; 11-10-2008 at 09:23 AM. Reason: Marked as solved

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi ss_bb,

    You would need to unprotect your worksheet at the beginning of the macro, then re-protect it at the end. For example:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    09-04-2007
    Posts
    127

    workbook's code errors coming

    thanks pjoaquin. Its working in that sheet. But I am getting the other problem related to the same issue in the same workbook.

    I have used some code code to the whole workbook so that during opening this workbook you are asked to give your name. I have used the below code:-
    Please Login or Register  to view this content.
    Now the same value ( name of the person who opens this workbook) & date with time will be autometically written in the B2 & C2 cell of my Main sheet.Main sheet is also protected by password "007" & only blue colored cells are unprotected for feeding the date. Now when I open this workbook then error is coming in this .Range("B2") = Ans (bold & underlined in the code). But when I add
    Please Login or Register  to view this content.
    &
    Please Login or Register  to view this content.
    in the above code then its working but all the cells in main sheet are getting unlocked.

    I have given a screen picture of my main sheet. COULD ANYONE HELP ME PLEASE.
    Attached Images Attached Images

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    The 'Locked' status of any cells should not be affected by the code. While it's true that the Main Sheet is unprotected at the beginning of the macro, allowing any cell to be edited, it is very quickly re-protected. So unless you have users that can edit cells in a fraction of a second, you shouldn't have anything to worry about.

    Since you're working with a specific sheet, rather than using 'ActiveSheet', use:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    09-04-2007
    Posts
    127
    Excellent!!! thanks a lot Pjoaquin

+ 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