+ Reply to Thread
Results 1 to 17 of 17

How to lock / protect the cells in different columns based on a date

  1. #1
    Registered User
    Join Date
    10-12-2013
    Location
    United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    21

    How to lock / protect the cells in different columns based on a date

    Hi
    I am new to the forum.
    Trying to incorporate the following in a worksheet:
    Lock the cells automatically in the columns that are older than 2 days or more
    Lock the cells corresponding to today and yesterday using a command button after entering X
    Copy the sheet multiple times with the same features
    Please help
    Nak
    Attached Files Attached Files

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: How to lock / protect the cells in different columns based on a date

    Hi there,

    It shouldn't be too difficult to lock (protect) all cells which relate to dates which are more than two days old.

    When you say:

    Lock the cells corresponding to today and yesterday using a command button after entering X
    do you mean that ALL cells which relate to today and yesterday should be locked, or that only the cells which contain an X should be locked?

    Please let me know and I'll see what I can do for you.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    10-12-2013
    Location
    United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: How to lock / protect the cells in different columns based on a date

    Customer Visit Report.xlsx
    Thanks Greg !
    I would like to optionally keep the latest 2 days open for data entry , but the whole column could be blocked electively after entering data if the user decides to do so.
    I will now upload another sheet which will be more specific and self explanatory.

    Please see the requirements below:

    I have to do a lot of simple field force activities analyses
    I don’t have a web based query system to pull data.
    So I use simple excel sheets link them and do the necessary analysis in the best possible manner I can J
    Here is an excel sheet
    All cells except I6:AM365 are protected. When a customer is visited, the user is required to put “X”or “Yes “in the corresponding date cell ( in the column ) against the name of the customer.
    Now I want the cells I6:125 to get locked, IF I5 >$G$4 and similarly for columns J: AM
    Because I want the user not to alter yesterday’s data after today. This allows a the user only 24 hrs time to report yesterday’s visits at the most.
    I have conditionally formatted the cells also. They turn grey if older than 1 day and are to be automatically locked and yesterday’s cells turn light pink because they are still unlocked. Today’s active column will be highlighted in dark pink. Columns representing tomorrow and beyond are open and non-colored.
    Can you help me with this ?
    I have used the date as =TODAY () in G2
    Day value in G3 - Day () returns the serial number
    Day value – 1 in G4
    Month is current month in G1
    For certain reasons I have given the dates in cells I5: AM5 serial numbers ( I don’t want real date formats there)
    Now I want the cells I6:AM325 to get locked as the dates are passed but with 1 day grace period
    Is there an optional way that though the cells up to day before yesterday get locked automatically, if the user enters the data in yesterday’s / todays columns ( if he is very punctual J- normally not ) and save the data by clicking a command button or so that the data cannot be altered by any one.
    N Vaidyar
    Also do you know if I can pull data from these sheets used by users remotely and consolidate them ? Via web or so ?

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: How to lock / protect the cells in different columns based on a date

    Hi again Noushad,

    A suggestion for you - would it be advisable to protect ALL of the "Visit Cells" EXCEPT those which refer to today and yesterday - i.e. to prevent visits being recorded in advance? I can implement this or I can implement what you asked for originally - neither of these options is very complicated, so just let me know which you prefer.

    Now a question regarding the way the workbook will be used in operation - when do you want the locking/unlocking operation to take place? Doing it each time the workbook is opened is quite easy, but it won't be applied if the user leaves the workbook open continuously. I can try to have the operation performed automatically at 23:59 each day, but my experience to date with the OnTime function has been less than 100% successful - maybe that's my fault or maybe it's due to using earlier versions of Excel.

    Regarding the User's button to lock the "Visit Cells" for today and yesterday - do you want the button to lock ALL of the cells for today and yesterday, or just those cells which have already had an X entered in them? Either option is equally easy to provide.

    The worksheet in your workbook is protected, but not password-protected. I presume you will want the final version to be password-protected. If so, will an administrator (you?) need a button to conveniently Unprotect/Protect the worksheet without having to enter the password each time? If so, let me know the UserName of the administrator(s) - e.g. Noushad - and I can include a button which will be visible only if the workbook has been opened by an administrator.

    If you like, I can also provide formatting which will hide the columns for days 29, 30 and 31 depending on the month involved.

    Please let me know what you need for each of the above.

    Regards,

    Greg M

  5. #5
    Registered User
    Join Date
    10-12-2013
    Location
    United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    21

    Smile Re: How to lock / protect the cells in different columns based on a date

    Hi Greg,
    I am really surprised about the way you have comprehended my concept and your passion to help me.
    So nice of you !
    I am greatly obliged
    Noushad


    Hi again Noushad,

    A suggestion for you - would it be advisable to protect ALL of the "Visit Cells" EXCEPT those which refer to today and yesterday - i.e. to prevent visits being recorded in advance? I can implement this or I can implement what you asked for originally - neither of these options is very complicated, so just let me know which you prefer.
    >>>>Yes, that would be wonderful. Only the 2 columns are open at any given point in time. Perfect And probably you could even hide the future date columns


    Now a question regarding the way the workbook will be used in operation - when do you want the locking/unlocking operation to take place? Doing it each time the workbook is opened is quite easy, but it won't be applied if the user leaves the workbook open continuously. I can try to have the operation performed automatically at 23:59 each day, but my experience to date with the OnTime function has been less than 100% successful - maybe that's my fault or maybe it's due to using earlier versions of Excel.
    >> Since I have used formula =Today () in cell G3 , the Day value will change ( G4 ) will change automatically and that should be the time cells are protected

    Regarding the User's button to lock the "Visit Cells" for today and yesterday - do you want the button to lock ALL of the cells for today and yesterday, or just those cells which have already had an X entered in them? Either option is equally easy to provide.
    >> Ideally the 2 columns can be unprotected for 2 days. However if the user wants to lock them as soon as the data entry is over , he can click a button which would prompt him to check the data entered and the cells are going to be locked permanently and no editing will be possible. This should apply to the columns in which the data has been entered ( the whole column). If data in both columns are entered both columns should be locked.

    The worksheet in your workbook is protected, but not password-protected. I presume you will want the final version to be password-protected. If so, will an administrator (you?) need a button to conveniently Unprotect/Protect the worksheet without having to enter the password each time? If so, let me know the UserName of the administrator(s) - e.g. Noushad - and I can include a button which will be visible only if the workbook has been opened by an administrator. ( I would like to have the password : ( will mail you separately)

    If you like, I can also provide formatting which will hide the columns for days 29, 30 and 31 depending on the month involved.

    Please let me know what you need for each of the above.

    Regards,

    Greg M
    Last edited by Noushad Vaidyar; 10-27-2013 at 09:35 AM.

  6. #6
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: How to lock / protect the cells in different columns based on a date

    Hi Noushad,

    Thanks for that information. I have implemented most of what you asked for, and will try to have the final version available to send you tomorrow (Monday).

    Regards,

    Greg M
    Last edited by Greg M; 10-27-2013 at 09:40 PM. Reason: Correction of minor typo.

  7. #7
    Registered User
    Join Date
    10-12-2013
    Location
    United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: How to lock / protect the cells in different columns based on a date

    Thanks Greg ! Great Help Indeed!

  8. #8
    Registered User
    Join Date
    10-12-2013
    Location
    United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: How to lock / protect the cells in different columns based on a date

    Hi again Greg
    Now that you have been able to sort out all my issues so systematically !!!!! , one final request more:
    Can I add another sheet as a Daily Call Report ?
    Please see the attached sample
    By entering the day value, I should be able to generate the Daily Report for that particular date.
    Then generate a PDF of the report and mail it to the address specified in the cells and cc
    I think a INDEX IFNA function and VBA code will be rquired for this
    Sorry to bother you again
    Attached Files Attached Files

  9. #9
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: How to lock / protect the cells in different columns based on a date

    Hi again Noushad,

    Take a look at the attached workbook and see what you think of it.

    A few points:

    The cell protection routine will be run automatically each time the workbook is opened, and also at midnight if the workbook happens to be open at that time.

    Only the "Visit Cells" associated with days up to and including Today are visible - cells associated with future dates are hidden.

    Only the "Visit Cells" associated with Yesterday and Today are unlocked - all other cells on the worksheet are locked.

    The "Lock" button (which the User uses to lock the "Visit Cells" for Yesterday and/or Today) moves along the row so that it is always positioned above the "Day Cells" for Yesterday and Today.

    When the User presses the "Lock" button, the "Visit Cells" are checked for entries - if entries are detected in a column, the User is prompted to confirm that the cells should be locked. No prompt is generated if no entries are detected. This is done for each of the two columns, Yesterday and Today.

    Near the top of the VBA CodeModule there is a statement which reads:

    Please Login or Register  to view this content.
    You should change the value of this Constant to whatever you use for your Windows UserId - when this is done, save and reopen the workbook and you should see the "Unprotect/Protect Worksheet" button in Cells I2:M3. This button will not be visible if the workbook is opened by anyone with a UserId different from your own.

    Is the formula used in Column H (Visits) correct? You have used the "SUM" function, but that will not work correctly if Visits are recorded by using an "X". Should numbers (1, 2) be used in this column instead?

    Now, before I look at your Daily Call Report, we need to consider what should happen at the end/beginning of the month. Do you intend to create a new worksheet for the new month? Yesterday's "Visit Cells" will no longer be visible if Today is the first day of the new month. Do you need to save a copy of the worksheet for the old month in a new "Archives" workbook and clear the "Visit Cells" so that they are available for the new month? Something else?

    Have a think about what you require and let me know.

    Regards,

    Greg M
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    10-12-2013
    Location
    United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: How to lock / protect the cells in different columns based on a date

    Hello Greg !
    Thanks a lot !
    I will revert to you with all my comments
    Great help indeed !!!
    Noushad

  11. #11
    Registered User
    Join Date
    10-12-2013
    Location
    United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: How to lock / protect the cells in different columns based on a date

    Archiving exactly as you mentioned
    PDF with time stamp to go to the e mail addresses mentioned( changeable)
    Attached Files Attached Files

  12. #12
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: How to lock / protect the cells in different columns based on a date

    Hi Noushad,

    Here's the latest version of the workbook - we're definitely making some progress

    My comments on the attached might be a bit too detailed to post here, so I've sent you a Private Message with them. I'll happily post them here if anyone else is interested!

    Regards,

    Greg M
    Attached Files Attached Files

  13. #13
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: How to lock / protect the cells in different columns based on a date

    Hi Noushad,

    Thanks for the comments in your Private Message.

    The attached workbook seems to be working ok. The creation of the .PDF file and the associated email have been added. We just need to decide whetherr the .PDF file should be deleted or retained and archived.

    I've had some thoughts about the archiving of the monthly worksheet and I'll let you know as soon as I have something worked out.

    Regards,

    Greg M
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    10-12-2013
    Location
    United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: How to lock / protect the cells in different columns based on a date

    Excellent solution !
    Big thank you Greg !
    I would like to add some valuable points to your reputation, please advise
    Noushad

  15. #15
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: How to lock / protect the cells in different columns based on a date

    Hi Noushad,

    You can add to my "reputation" by looking at my posts in the Forum. In the bottom left-hand corner there is an "Add Reputation" button. Just click on that and you can add points and comments as you wish.

    I've added some more details to the version of the workbook which contains your confidential data, and I'll email it to you.

    Just in case any other Forum users are interested, I hope to post the final version with "sample" data here when everything has been completed.

    Regards,

    Greg M

  16. #16
    Registered User
    Join Date
    05-01-2020
    Location
    Greece
    MS-Off Ver
    365
    Posts
    1

    Re: How to lock / protect the cells in different columns based on a date

    Hi Greg
    I' m new in this forum. My Vba Knowlwdge is beginer level but i can recognize that the solution of "026 - Customer Visit Report - 7.xlsm"‎
    was an Excellent job. I was wondering if you have moved on to any solution of the monthly archiving (that is the one that interests me). Please i'd like to send me the way the file works just like you done Noushad.
    Thanks alot

  17. #17
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,570

    Re: How to lock / protect the cells in different columns based on a date

    Administrative Note:

    Hello kspirop and Welcome to Excel Forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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. Lock (Protect) Row based on a value, but not prohibit filtering
    By jdmill80 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2012, 12:42 PM
  2. how to lock/protect automaticaly columns with dates less then curent date
    By petre_ in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-27-2012, 07:32 AM
  3. lock and protect all but certain cells
    By JediMaster in forum Excel General
    Replies: 5
    Last Post: 08-20-2010, 09:52 AM
  4. Can I protect/lock only the cells containing formulas?
    By JLee98 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2007, 10:17 PM
  5. [SOLVED] Can I protect/lock columns AND set custom views?
    By Meltad in forum Excel General
    Replies: 0
    Last Post: 07-31-2006, 11:08 AM

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