+ Reply to Thread
Results 1 to 7 of 7

Lock all non-empty cells

  1. #1
    Registered User
    Join Date
    10-08-2009
    Location
    Poland
    MS-Off Ver
    Excel 2003
    Posts
    19

    Lock all non-empty cells

    Hi.
    Here is my situation.
    I have a workbook with some sheets (sample as a attachment).
    I want all the cells that aren't empty (!= "") to be Locked, and all other UnLocked, so when I protect it only unlocked cells could be modified.

    Another solution that is 100% satisfying (and which I've been trying to figure out) is to Lock a minimum rectangle that covers all the non-empty cells (in the attached .xls coloured with yellow).

    So far I've written this:
    Please Login or Register  to view this content.
    First Loop DOES work, but the second Locks more than needed (sometimes) and It's the main problem I've been experiencing.

    Please Help, thanks in advance.
    Mike
    Attached Files Attached Files

  2. #2
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Lock all non-empty cells

    Try it out
    Please Login or Register  to view this content.
    Last edited by contaminated; 02-24-2010 at 08:24 AM.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  3. #3
    Registered User
    Join Date
    10-08-2009
    Location
    Poland
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Lock all non-empty cells

    Hi, thanks for reply but this doesnt work. On my real workbook i have 2 sheets.
    On first, your sub locks empty cells and unlocks not empty ones,
    On second sheet it does nothing (all cells are locked).

  4. #4
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Lock all non-empty cells

    I have edited my previous post.
    Please take a look again...

  5. #5
    Registered User
    Join Date
    10-08-2009
    Location
    Poland
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Lock all non-empty cells

    Again, it doesn't work. This time it blocks some empty cells, and others not.
    On another sheet it blocks everything, despite being empty or not.

    I've attached current .xls that I tried your sub on.
    Attached Files Attached Files

  6. #6
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Lock all non-empty cells

    Hi
    I apologise for misunderstanding first. Below code Protects all non empty cells and unblocks all blank cells
    First unprotect your sheets then run this code, else u'll get Unable to set lock property of range class error.

    Please Login or Register  to view this content.
    Last edited by contaminated; 02-24-2010 at 09:07 AM.

  7. #7
    Registered User
    Join Date
    10-08-2009
    Location
    Poland
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Lock all non-empty cells

    Yes it works. But What about my 2nd solution that I was working on ? (lock smallest rectangle that covers the nonempty cells?) In some cases this would be more useful than the one proposed by you (working really good right now:P).
    Last edited by knab; 02-24-2010 at 09:48 AM.

+ 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