+ Reply to Thread
Results 1 to 9 of 9

Clearing unlocked cells

  1. #1
    Registered User
    Join Date
    01-19-2010
    Location
    Antwerp,Belgium
    MS-Off Ver
    Excel 2003
    Posts
    16

    Clearing unlocked cells

    Hello all,

    I have locked an entire worksheet, except a specific range X. In the next step I run a macro that clears this range in VBA. After clearing the range, all the cells in it are suddenly locked.

    Why is this happening?
    And how can it be solved?

    Thank you,

    Lanox
    Last edited by Lanox; 01-10-2012 at 09:25 AM. Reason: Problem solved

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Clearing unlocked cells

    hat code are you using?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,453

    Re: Clearing unlocked cells

    Guess it depends on what your code does.

    Can you post the code? Ideally, in a sample workbook that demonstrates the problem.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    01-19-2010
    Location
    Antwerp,Belgium
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Clearing unlocked cells

    range("X").clear

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,453

    Re: Clearing unlocked cells

    If you seriously want someone to look at your problem, please post all the code so it can be seen in context.

    In order to test your code, it is highly likely that you will need to post a sample workbook.


    Regards, TMS

  6. #6
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Clearing unlocked cells

    Try using ClearContents instead. I suspect you are resetting the style to Normal, which by default probably has the Locked property set to True.
    Good luck.

  7. #7
    Registered User
    Join Date
    01-19-2010
    Location
    Antwerp,Belgium
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Clearing unlocked cells

    Hi all,

    thx for all the remarks.

    I had an example sheet with the problem, but the settings here at work prevent me from uploading it. Sorry for that. The line of code was the only line in a subroutine and demonstrated the problem.

    The problem is exactly what OnErrorGoto0 says: the Locked property is part of the cell formatting and is reseted to its defaults when the cell is cleared. The default setting makes it a locked cell.

    The solution that worked for me has two parts. I first had to allow format changes by the user in the protection options, and then I copied an empty cell with the desired formats and properties to the entire range. It is not 100% safe since the user could alter this empty cell too, but you can make it hard to access it by putting a locked cell in the same column and set the column width to 0.

    Thanks again to everyone who took the time to look at my problem.

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Clearing unlocked cells

    Did it not work using ClearContents instead of Clear? That should not affect formatting.

  9. #9
    Registered User
    Join Date
    01-19-2010
    Location
    Antwerp,Belgium
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Clearing unlocked cells

    In my case it didn't because of some other features of the sheet. The range contains merged cells and might have to be overwritten by merged cells of a different size. ClearContents doesn't eliminate this part of the formats, so additional code would be needed. My solution was easier in this particular case.

+ 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