+ Reply to Thread
Results 1 to 7 of 7

I need a macro to lock only cells that a contain a formula

  1. #1
    Registered User
    Join Date
    01-20-2011
    Location
    Hants, UK
    MS-Off Ver
    Excel 2010
    Posts
    9

    I need a macro to lock only cells that a contain a formula

    Many of my spreadsheets are very basic and are used by people who have no knowledge of spreadsheets (if I said "dont overtype a formula", they wouldnt know what I was talking about). I have tried putting comments that say "please dont type in this column/row/cell" to no avail.
    I still get the spreadsheet back saying "its stopped working".

    99% of the time it is because they have overtyped a formula.

    Before I ship a worksheet to them I now lock and protect any ( and only) those cells that contain a formula by:

    1) click on cell 0,0 to highlight all cells in the spreadsheet
    2) click on format cells -> unlock cells
    3) show all cells containing formulas by using keys cntrl + `
    4) highlight all these cells
    5) click on format cells -> lock cells
    6) click on format cells -> protect sheet ( no password)

    I would like to use a general macro to do the above for any worksheet. Any ideas on how to select and highlight only cells which contain a formula?
    Last edited by roybranagan; 01-19-2012 at 05:35 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: I need a macro to lock only cells that a contain a formula

    Roy,

    I think if I get you started you can do this one yourself. This bit of code:
    Please Login or Register  to view this content.
    will select any cell on the activesheet containing a formula.

    So, what I would do is turn on your macro recorder and run through your whole routine (as outlined earlier), knowing that parts 3 and 4 will be covered by the code I've provided. The recorded macro, with the code provided, should be the basis for your "general" macro. Let me know if more help is needed.
    Last edited by jomili; 01-17-2012 at 10:40 AM.

  3. #3
    Registered User
    Join Date
    01-20-2011
    Location
    Hants, UK
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: I need a macro to lock only cells that a contain a formula

    Jomili,
    excellent suggestion - it seems to work for all but one test. When I have a sheet without any formula in a cell the macro fails with Run-time error '1004' no cells were found
    Roy

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: I need a macro to lock only cells that a contain a formula

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: I need a macro to lock only cells that a contain a formula

    Nilem showed the way. Try this as the full macro (untested):
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-20-2011
    Location
    Hants, UK
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: I need a macro to lock only cells that a contain a formula

    Jomili and Nilem
    Many thanks - that worked fine - I will continue with a few more tests and let you know tomorrow

  7. #7
    Registered User
    Join Date
    01-20-2011
    Location
    Hants, UK
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: I need a macro to lock only cells that a contain a formula

    Thanks guys
    just what I needed

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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