+ Reply to Thread
Results 1 to 24 of 24

Macro code that runs despite specific cells being locked.

  1. #1
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Thumbs up Macro code that runs despite specific cells being locked.

    I have a workbook with six sheets. It has pop up userforms macro infused autofills, clears and automtic saves.

    Is there a macro code that will lock specific cells while allowing other specific cells to remain unlocked. Where by my code will still run?

    Unlocked Cells are Sheet 1 (D8:J8,D9:J9,D12:D29,F12,G12,F15,G15,F18,G18,F21,G21,F24,G24,F27,G27,F30,F31) AND Sheet 6 (C8:F8,C9:F9,B13:F13,B14:F14,B15:F15,B16:F16,B17:F17,B18:F18,C33:D33,

    Is their a way to do this without a password?

    Thank you for your help.
    Last edited by TBM; 01-21-2016 at 01:05 PM. Reason: Clarification

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro code that runs despite specific cells being locked.

    Sure. In your code Unpassword protect the sheet. Have the code run. The re password protect your sheet. Just good search VBA password protect sheet
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    That is not exactly what I am looking for.
    I am looking for information on the first part of my post.

    I want a permanent lock on specific cells. As well as specific cells remaining unlocked. Where by my code will still run.

    Unlocked Cells are Sheet 1 (D8:J8,D9:J9,D12:D29,F12,G12,F15,G15,F18,G18,F21,G21,F24,G24,F27,G27,F30,F31) AND Sheet 6 (C8:F8,C9:F9,B13:F13,B14:F14,B15:F15,B16:F16,B17:F17,B18:F18,C33:D33,

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro code that runs despite specific cells being locked.

    I want a permanent lock on specific cells. As well as specific cells remaining unlocked. Where by my code will still run.
    Still the same answer. Lock the cells you want locked. Unlock the ones you don't. Password protect the sheets. That translates into a permanent lock. You said "Where by my code will still run"; your code will still run just fine if you unpassword protect the sheets in code as i described above.

  5. #5
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    Is this the kind of code that you are thinking I should be using

    If yes, This is not what I meant. Maybe Ill have to rethink what it is I am asking.

    Anyway regardless, i appreciate you helping me.

    Thanks

    Sheets("Sheet1").Unprotect Password:="PasswordGoesHere"
    'Rest of your code goes here
    Sheets("Sheet1").Protect Password:="PasswordGoesHere"

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro code that runs despite specific cells being locked.

    Is this the kind of code that you are thinking I should be using
    That is correct

  7. #7
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    When using That Code, how do I add a couple more sheets?

  8. #8
    Forum Contributor
    Join Date
    05-23-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Macro code that runs despite specific cells being locked.

    Please Login or Register  to view this content.
    Assuming this is what you meant, you can use this to protect/unprotect any sheet as long as its specified. If you are just looking to do the activesheet, you can specify

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    Thanks for your reply
    I Can get it to work with one sheet, however, I have 3 sheets I want unprotected

  10. #10
    Forum Contributor
    Join Date
    05-23-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Macro code that runs despite specific cells being locked.

    You just have to list three separate instances:

    Please Login or Register  to view this content.
    With your other code inbetween here.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    That does not work either.
    Thanks for your reply

  12. #12
    Forum Contributor
    Join Date
    05-23-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Macro code that runs despite specific cells being locked.

    Yes...but it should. Are you including the quotations around the sheet name(s)?

    Or can you share your code so we can see what might be the bigger problem?

  13. #13
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    Please Login or Register  to view this content.
    here is my dealio

    thanks

  14. #14
    Forum Contributor
    Join Date
    05-23-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2013
    Posts
    259

    Re: Macro code that runs despite specific cells being locked.

    I'll assume yes, but are the spaces in your sheet names actually present in your sheet names?

  15. #15
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro code that runs despite specific cells being locked.

    If the password to all your sheets is the same you can loop through all the worksheets, which would avoid any name issues:

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    Thanks for your reply
    Yes they are

  17. #17
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    Thanks for your reply.
    ok so I have tried this before.
    The problem is that for some reason the new error wont allow the clearcontents to clear in merged cells. where it did not before.
    Then I unmerged all affected cells. Then it was a different error. Then soon I was getting problems all over my work book.

    I am going to post my entire workbook.

    hope fully someone sees something I am not.

    Thank you.
    Last edited by TBM; 01-26-2016 at 07:14 PM.

  18. #18
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro code that runs despite specific cells being locked.

    There is a lot going on in your workbook. A LOT. Can you be very specific on all aspects of your issue (i.e. Which macro you are trying to run. Which worksheet are we dealing with. What cells need to be locked/unlocked. Are any of the userforms involved. Etc). At this point it is a needle in a haystack.

  19. #19
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    Thank you for your continued help.

    So The way My book works:

    Sheet 1 Is My invoice input area

    It has two User forms that pop up. one for customers command button "customer profile" activates it (data come from sheet 3)......the second for salesman command button "salesman profile" activates it(data comes from sheet 5)..... They both populate a series of cells on sheet1.

    The command button "next invoice number" checks to see if "specific cells" are filled. If they are not, then they are highlighted yellow and the macros is stopped until they are filled.
    If they are filled then an "register" on sheet 4 is filled with data.
    Then a pdf of sheet 2 is created and sent to a specific folder.
    as well, a xls copy of sheet 2 is also stored in a specified folder.
    lastly specific cells are cleared and the invoice number is increased by one.

    At the begining of this module is a macro that determines the order of all of these items and executes them.

    Sheet 2 is a finished copy of sheet1 and is essentially there for the user to easily see there work. As sheet 1 has formulas that are based on different types of work etc..

    sheet 6 essentially does the same as sheet 1 except it is for estimates rather than invoices and does not need a finished copy

    So all of these user forms, command buttons, modules and code work perfectly while un protected. when i protect sheets (1), (2) (4) and (6). i recieved run time errors.

    I tried running the various suggestions of code in there proper places. All of them However, cause errors.

    for example The code that unprotects the entire workbook, then runs the code then protects afterwards, gets an error in the "highlight unfilled cells" code. The code says cant do this to a merged cell. so unmerged all the cells and i ended up with the same error.Test with protection code.xlsm
    Last edited by TBM; 01-26-2016 at 07:06 PM.

  20. #20
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro code that runs despite specific cells being locked.

    Good explanation. With that being said, this worked just fine for your highlight macro (I commented out the other codes for obvious reasons)

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    So I added an updated version of my workbook
    all of the modules and forms have un protect and protect formulas in them
    only two of the command buttons are now working sheet 6 customer profile and salesman profile

    The following do not work
    sheet 1 all 3 command buttons
    sheet 6 next estimate command button.

    Why is the last part of my project so frustrating.

    Hopefully you will be able to trouble shoot this thanks

  22. #22
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro code that runs despite specific cells being locked.

    I am going to say this as straightforward as I can, not with malicious intent. I think all the issues you are experiencing are simple coding error. You need to make sure you pay attention to every little detail, which can be very challenging sometimes when you have as much stuff going on as what you have.

    sheet 1 all 3 command buttons
    You misnamed a sheet. "1 Invoice Print" does not exist.
    Please Login or Register  to view this content.
    sheet 6 next estimate command button.
    I suspect it is incorrectly pointing to an ineligible directory. Only you can solve this since it is your directory.
    Last edited by stnkynts; 01-26-2016 at 07:54 PM.

  23. #23
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    None taken,
    I will Go over it with a little more care.
    You sound like me when I am chatting with my employees and the answer is right in front them.
    Thanks again

  24. #24
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Surrey B.C.
    MS-Off Ver
    2013
    Posts
    155

    Re: Macro code that runs despite specific cells being locked.

    This is solved But my brain hurts to test and implement. I think I will Just run it unprotected and wing it. perhaps ill revisit this another year.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using Worksheet_SelectionChange, so code only runs when specific cells are changed
    By Kristine T. in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-20-2015, 08:49 PM
  2. Can i avoid Locked Cells Using this Code getting Updated How can i edit this code
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-01-2014, 03:27 AM
  3. Cell/Range locked after automated resize code runs under Worksheet_Change tab
    By element6 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2014, 06:20 PM
  4. [SOLVED] Macro only runs on specific sheet name
    By cymraeg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 03:43 PM
  5. Error when running macro at a specific time: only runs once
    By Axildoofay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-09-2013, 05:54 AM
  6. Macro runs when i click on specific cell
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-19-2009, 05:28 AM
  7. Code runs only if a specific page of the MultiPage is selected
    By Gabor in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-18-2009, 07:18 PM

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