Can I use a macro to protect a cell in an excel spreadsheet with a password?











up vote
0
down vote

favorite












I have an excel spreadsheet set up as a timeclock . The employee opens their timeclock file for the week and fills in the week ending date in the designated spot. From here on out, only the mouse is used for input. The employee selects the proper cell for the day of the week and the action of punching in, going to lunch, back from lunch and going home. After they position the cursor over the correct cell, they click on a button (a button linked to a macro) that fills in the correct time for the action. I can't figure out how to keep them from just going to the cell they want and typing in whatever time they want. I tried adding protecting the cell with a password as part of the button macro but haven't been able to get that to work. Anybody have a way to protect the cells so the employee can't alter the times? Or, is there just an easier way to do this all together?










share|improve this question






















  • My observation: 1. Seems the file is in Protected mode and the Macro behind allows only the mouse to move and click on button. Now what you are looking for is allow the user to input data in cells and must be protected then after.
    – Rajesh S
    Dec 1 at 6:02












  • Cont...,The very first need is just share the Macro which restricts the Cell pointer movement around file, help us to understand the process. And yes it's possible for the user to protect data after been entered. ☺
    – Rajesh S
    Dec 1 at 6:05












  • Rajesh, thanks for your reply. To answer your question about restricting pointer movement within the sheet, the cells I don't want the user to go to are protected and the protection prevents the user from selecting locked cells. The user can only select the cells I want them to use. Once they have entered the time into a proper cell using the button for in, out or whatever, I don't want them to be able to go back to that cell. Single use, protected after the first use. I don't want the user to protect the data, I want it to retain the value it got the first time.
    – Paul Y
    Dec 6 at 3:39










  • cont,, since already you have worked with the protected area so the next need is how to restrict user to edit the new data. if you feel I can suggest you Macro will help you to apply protection on data been entered. Just confirm if you need it through comments. ☺
    – Rajesh S
    Dec 6 at 4:37












  • Rajesh, if you can send me the macro, I would certainly give it a try. Thanks
    – Paul Y
    Dec 7 at 1:07















up vote
0
down vote

favorite












I have an excel spreadsheet set up as a timeclock . The employee opens their timeclock file for the week and fills in the week ending date in the designated spot. From here on out, only the mouse is used for input. The employee selects the proper cell for the day of the week and the action of punching in, going to lunch, back from lunch and going home. After they position the cursor over the correct cell, they click on a button (a button linked to a macro) that fills in the correct time for the action. I can't figure out how to keep them from just going to the cell they want and typing in whatever time they want. I tried adding protecting the cell with a password as part of the button macro but haven't been able to get that to work. Anybody have a way to protect the cells so the employee can't alter the times? Or, is there just an easier way to do this all together?










share|improve this question






















  • My observation: 1. Seems the file is in Protected mode and the Macro behind allows only the mouse to move and click on button. Now what you are looking for is allow the user to input data in cells and must be protected then after.
    – Rajesh S
    Dec 1 at 6:02












  • Cont...,The very first need is just share the Macro which restricts the Cell pointer movement around file, help us to understand the process. And yes it's possible for the user to protect data after been entered. ☺
    – Rajesh S
    Dec 1 at 6:05












  • Rajesh, thanks for your reply. To answer your question about restricting pointer movement within the sheet, the cells I don't want the user to go to are protected and the protection prevents the user from selecting locked cells. The user can only select the cells I want them to use. Once they have entered the time into a proper cell using the button for in, out or whatever, I don't want them to be able to go back to that cell. Single use, protected after the first use. I don't want the user to protect the data, I want it to retain the value it got the first time.
    – Paul Y
    Dec 6 at 3:39










  • cont,, since already you have worked with the protected area so the next need is how to restrict user to edit the new data. if you feel I can suggest you Macro will help you to apply protection on data been entered. Just confirm if you need it through comments. ☺
    – Rajesh S
    Dec 6 at 4:37












  • Rajesh, if you can send me the macro, I would certainly give it a try. Thanks
    – Paul Y
    Dec 7 at 1:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have an excel spreadsheet set up as a timeclock . The employee opens their timeclock file for the week and fills in the week ending date in the designated spot. From here on out, only the mouse is used for input. The employee selects the proper cell for the day of the week and the action of punching in, going to lunch, back from lunch and going home. After they position the cursor over the correct cell, they click on a button (a button linked to a macro) that fills in the correct time for the action. I can't figure out how to keep them from just going to the cell they want and typing in whatever time they want. I tried adding protecting the cell with a password as part of the button macro but haven't been able to get that to work. Anybody have a way to protect the cells so the employee can't alter the times? Or, is there just an easier way to do this all together?










share|improve this question













I have an excel spreadsheet set up as a timeclock . The employee opens their timeclock file for the week and fills in the week ending date in the designated spot. From here on out, only the mouse is used for input. The employee selects the proper cell for the day of the week and the action of punching in, going to lunch, back from lunch and going home. After they position the cursor over the correct cell, they click on a button (a button linked to a macro) that fills in the correct time for the action. I can't figure out how to keep them from just going to the cell they want and typing in whatever time they want. I tried adding protecting the cell with a password as part of the button macro but haven't been able to get that to work. Anybody have a way to protect the cells so the employee can't alter the times? Or, is there just an easier way to do this all together?







microsoft-excel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 1 at 3:07









Paul Y

1




1












  • My observation: 1. Seems the file is in Protected mode and the Macro behind allows only the mouse to move and click on button. Now what you are looking for is allow the user to input data in cells and must be protected then after.
    – Rajesh S
    Dec 1 at 6:02












  • Cont...,The very first need is just share the Macro which restricts the Cell pointer movement around file, help us to understand the process. And yes it's possible for the user to protect data after been entered. ☺
    – Rajesh S
    Dec 1 at 6:05












  • Rajesh, thanks for your reply. To answer your question about restricting pointer movement within the sheet, the cells I don't want the user to go to are protected and the protection prevents the user from selecting locked cells. The user can only select the cells I want them to use. Once they have entered the time into a proper cell using the button for in, out or whatever, I don't want them to be able to go back to that cell. Single use, protected after the first use. I don't want the user to protect the data, I want it to retain the value it got the first time.
    – Paul Y
    Dec 6 at 3:39










  • cont,, since already you have worked with the protected area so the next need is how to restrict user to edit the new data. if you feel I can suggest you Macro will help you to apply protection on data been entered. Just confirm if you need it through comments. ☺
    – Rajesh S
    Dec 6 at 4:37












  • Rajesh, if you can send me the macro, I would certainly give it a try. Thanks
    – Paul Y
    Dec 7 at 1:07


















  • My observation: 1. Seems the file is in Protected mode and the Macro behind allows only the mouse to move and click on button. Now what you are looking for is allow the user to input data in cells and must be protected then after.
    – Rajesh S
    Dec 1 at 6:02












  • Cont...,The very first need is just share the Macro which restricts the Cell pointer movement around file, help us to understand the process. And yes it's possible for the user to protect data after been entered. ☺
    – Rajesh S
    Dec 1 at 6:05












  • Rajesh, thanks for your reply. To answer your question about restricting pointer movement within the sheet, the cells I don't want the user to go to are protected and the protection prevents the user from selecting locked cells. The user can only select the cells I want them to use. Once they have entered the time into a proper cell using the button for in, out or whatever, I don't want them to be able to go back to that cell. Single use, protected after the first use. I don't want the user to protect the data, I want it to retain the value it got the first time.
    – Paul Y
    Dec 6 at 3:39










  • cont,, since already you have worked with the protected area so the next need is how to restrict user to edit the new data. if you feel I can suggest you Macro will help you to apply protection on data been entered. Just confirm if you need it through comments. ☺
    – Rajesh S
    Dec 6 at 4:37












  • Rajesh, if you can send me the macro, I would certainly give it a try. Thanks
    – Paul Y
    Dec 7 at 1:07
















My observation: 1. Seems the file is in Protected mode and the Macro behind allows only the mouse to move and click on button. Now what you are looking for is allow the user to input data in cells and must be protected then after.
– Rajesh S
Dec 1 at 6:02






My observation: 1. Seems the file is in Protected mode and the Macro behind allows only the mouse to move and click on button. Now what you are looking for is allow the user to input data in cells and must be protected then after.
– Rajesh S
Dec 1 at 6:02














Cont...,The very first need is just share the Macro which restricts the Cell pointer movement around file, help us to understand the process. And yes it's possible for the user to protect data after been entered. ☺
– Rajesh S
Dec 1 at 6:05






Cont...,The very first need is just share the Macro which restricts the Cell pointer movement around file, help us to understand the process. And yes it's possible for the user to protect data after been entered. ☺
– Rajesh S
Dec 1 at 6:05














Rajesh, thanks for your reply. To answer your question about restricting pointer movement within the sheet, the cells I don't want the user to go to are protected and the protection prevents the user from selecting locked cells. The user can only select the cells I want them to use. Once they have entered the time into a proper cell using the button for in, out or whatever, I don't want them to be able to go back to that cell. Single use, protected after the first use. I don't want the user to protect the data, I want it to retain the value it got the first time.
– Paul Y
Dec 6 at 3:39




Rajesh, thanks for your reply. To answer your question about restricting pointer movement within the sheet, the cells I don't want the user to go to are protected and the protection prevents the user from selecting locked cells. The user can only select the cells I want them to use. Once they have entered the time into a proper cell using the button for in, out or whatever, I don't want them to be able to go back to that cell. Single use, protected after the first use. I don't want the user to protect the data, I want it to retain the value it got the first time.
– Paul Y
Dec 6 at 3:39












cont,, since already you have worked with the protected area so the next need is how to restrict user to edit the new data. if you feel I can suggest you Macro will help you to apply protection on data been entered. Just confirm if you need it through comments. ☺
– Rajesh S
Dec 6 at 4:37






cont,, since already you have worked with the protected area so the next need is how to restrict user to edit the new data. if you feel I can suggest you Macro will help you to apply protection on data been entered. Just confirm if you need it through comments. ☺
– Rajesh S
Dec 6 at 4:37














Rajesh, if you can send me the macro, I would certainly give it a try. Thanks
– Paul Y
Dec 7 at 1:07




Rajesh, if you can send me the macro, I would certainly give it a try. Thanks
– Paul Y
Dec 7 at 1:07










2 Answers
2






active

oldest

votes

















up vote
0
down vote













Your users have access to write to the Excel file...



I don't think you can technically enforce this within Excel; I think you want an alternative software. I admire your skill with Excel macros though.



To elaborate:




  • If the user can modify the cell, then it isn't protected from the user simply modifying the cell on their own (typing in a value).

  • If the user cannot modify the cell, then it is protected from the user just typing in a value, but they also cannot cause the correct information to be written to it from a macro.


This is distinct from encrypting cells, which prevents even reading without the password.



I think there is a lot of time-card software out there, and most of it can probably export collected data into Excel. I would expand my horizons beyond spreadsheets if I were in your position.






share|improve this answer




























    up vote
    0
    down vote













    You may disallow changes to cells by a VBA event handler:



    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    With Target
    If If Not Intersect(Target, Range("A1:B10")) Is Nothing Then Application.Undo
    End With
    Application.EnableEvents = True
    End Sub


    I don't know if setting the value of cells via a VBA macro causes this event
    to fire. I know that it doesn't fire for changes induced by formulas.
    But you may easily define a global variable for allowing changes to be set
    before changing the cell and unset it afterward.



    You might also try to trap the Worksheet_SelectionChange event, to prevent the
    user from positioning the cursor inside the cell. You may for the disallowed
    cells re-position the cursor to some predefined cell (such as A1),
    or write some more complicated code to remember the last allowed cursor position
    and reposition to it.






    share|improve this answer





















    • hrrymc, thanks for your reply. You are speaking over my head. Can I cut and paste that into a macro and try it after changing the range to suit my needs?
      – Paul Y
      Dec 6 at 3:43










    • It should probably work. I recommend studying the subject : VBA is actually not very complicated, except for some ugly syntax. Take a look at the excel-easy tutorials, especially at "Create a Macro" and "Events". There are lots of other posts available on Internet, so you may search for specific questions, or if not found then come back to our site.
      – harrymc
      Dec 6 at 7:31











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1379886%2fcan-i-use-a-macro-to-protect-a-cell-in-an-excel-spreadsheet-with-a-password%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Your users have access to write to the Excel file...



    I don't think you can technically enforce this within Excel; I think you want an alternative software. I admire your skill with Excel macros though.



    To elaborate:




    • If the user can modify the cell, then it isn't protected from the user simply modifying the cell on their own (typing in a value).

    • If the user cannot modify the cell, then it is protected from the user just typing in a value, but they also cannot cause the correct information to be written to it from a macro.


    This is distinct from encrypting cells, which prevents even reading without the password.



    I think there is a lot of time-card software out there, and most of it can probably export collected data into Excel. I would expand my horizons beyond spreadsheets if I were in your position.






    share|improve this answer

























      up vote
      0
      down vote













      Your users have access to write to the Excel file...



      I don't think you can technically enforce this within Excel; I think you want an alternative software. I admire your skill with Excel macros though.



      To elaborate:




      • If the user can modify the cell, then it isn't protected from the user simply modifying the cell on their own (typing in a value).

      • If the user cannot modify the cell, then it is protected from the user just typing in a value, but they also cannot cause the correct information to be written to it from a macro.


      This is distinct from encrypting cells, which prevents even reading without the password.



      I think there is a lot of time-card software out there, and most of it can probably export collected data into Excel. I would expand my horizons beyond spreadsheets if I were in your position.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Your users have access to write to the Excel file...



        I don't think you can technically enforce this within Excel; I think you want an alternative software. I admire your skill with Excel macros though.



        To elaborate:




        • If the user can modify the cell, then it isn't protected from the user simply modifying the cell on their own (typing in a value).

        • If the user cannot modify the cell, then it is protected from the user just typing in a value, but they also cannot cause the correct information to be written to it from a macro.


        This is distinct from encrypting cells, which prevents even reading without the password.



        I think there is a lot of time-card software out there, and most of it can probably export collected data into Excel. I would expand my horizons beyond spreadsheets if I were in your position.






        share|improve this answer












        Your users have access to write to the Excel file...



        I don't think you can technically enforce this within Excel; I think you want an alternative software. I admire your skill with Excel macros though.



        To elaborate:




        • If the user can modify the cell, then it isn't protected from the user simply modifying the cell on their own (typing in a value).

        • If the user cannot modify the cell, then it is protected from the user just typing in a value, but they also cannot cause the correct information to be written to it from a macro.


        This is distinct from encrypting cells, which prevents even reading without the password.



        I think there is a lot of time-card software out there, and most of it can probably export collected data into Excel. I would expand my horizons beyond spreadsheets if I were in your position.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 1 at 5:48









        Slartibartfast

        6,18621724




        6,18621724
























            up vote
            0
            down vote













            You may disallow changes to cells by a VBA event handler:



            Private Sub Worksheet_Change(ByVal Target As Range)
            Application.EnableEvents = False
            With Target
            If If Not Intersect(Target, Range("A1:B10")) Is Nothing Then Application.Undo
            End With
            Application.EnableEvents = True
            End Sub


            I don't know if setting the value of cells via a VBA macro causes this event
            to fire. I know that it doesn't fire for changes induced by formulas.
            But you may easily define a global variable for allowing changes to be set
            before changing the cell and unset it afterward.



            You might also try to trap the Worksheet_SelectionChange event, to prevent the
            user from positioning the cursor inside the cell. You may for the disallowed
            cells re-position the cursor to some predefined cell (such as A1),
            or write some more complicated code to remember the last allowed cursor position
            and reposition to it.






            share|improve this answer





















            • hrrymc, thanks for your reply. You are speaking over my head. Can I cut and paste that into a macro and try it after changing the range to suit my needs?
              – Paul Y
              Dec 6 at 3:43










            • It should probably work. I recommend studying the subject : VBA is actually not very complicated, except for some ugly syntax. Take a look at the excel-easy tutorials, especially at "Create a Macro" and "Events". There are lots of other posts available on Internet, so you may search for specific questions, or if not found then come back to our site.
              – harrymc
              Dec 6 at 7:31















            up vote
            0
            down vote













            You may disallow changes to cells by a VBA event handler:



            Private Sub Worksheet_Change(ByVal Target As Range)
            Application.EnableEvents = False
            With Target
            If If Not Intersect(Target, Range("A1:B10")) Is Nothing Then Application.Undo
            End With
            Application.EnableEvents = True
            End Sub


            I don't know if setting the value of cells via a VBA macro causes this event
            to fire. I know that it doesn't fire for changes induced by formulas.
            But you may easily define a global variable for allowing changes to be set
            before changing the cell and unset it afterward.



            You might also try to trap the Worksheet_SelectionChange event, to prevent the
            user from positioning the cursor inside the cell. You may for the disallowed
            cells re-position the cursor to some predefined cell (such as A1),
            or write some more complicated code to remember the last allowed cursor position
            and reposition to it.






            share|improve this answer





















            • hrrymc, thanks for your reply. You are speaking over my head. Can I cut and paste that into a macro and try it after changing the range to suit my needs?
              – Paul Y
              Dec 6 at 3:43










            • It should probably work. I recommend studying the subject : VBA is actually not very complicated, except for some ugly syntax. Take a look at the excel-easy tutorials, especially at "Create a Macro" and "Events". There are lots of other posts available on Internet, so you may search for specific questions, or if not found then come back to our site.
              – harrymc
              Dec 6 at 7:31













            up vote
            0
            down vote










            up vote
            0
            down vote









            You may disallow changes to cells by a VBA event handler:



            Private Sub Worksheet_Change(ByVal Target As Range)
            Application.EnableEvents = False
            With Target
            If If Not Intersect(Target, Range("A1:B10")) Is Nothing Then Application.Undo
            End With
            Application.EnableEvents = True
            End Sub


            I don't know if setting the value of cells via a VBA macro causes this event
            to fire. I know that it doesn't fire for changes induced by formulas.
            But you may easily define a global variable for allowing changes to be set
            before changing the cell and unset it afterward.



            You might also try to trap the Worksheet_SelectionChange event, to prevent the
            user from positioning the cursor inside the cell. You may for the disallowed
            cells re-position the cursor to some predefined cell (such as A1),
            or write some more complicated code to remember the last allowed cursor position
            and reposition to it.






            share|improve this answer












            You may disallow changes to cells by a VBA event handler:



            Private Sub Worksheet_Change(ByVal Target As Range)
            Application.EnableEvents = False
            With Target
            If If Not Intersect(Target, Range("A1:B10")) Is Nothing Then Application.Undo
            End With
            Application.EnableEvents = True
            End Sub


            I don't know if setting the value of cells via a VBA macro causes this event
            to fire. I know that it doesn't fire for changes induced by formulas.
            But you may easily define a global variable for allowing changes to be set
            before changing the cell and unset it afterward.



            You might also try to trap the Worksheet_SelectionChange event, to prevent the
            user from positioning the cursor inside the cell. You may for the disallowed
            cells re-position the cursor to some predefined cell (such as A1),
            or write some more complicated code to remember the last allowed cursor position
            and reposition to it.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 1 at 10:59









            harrymc

            251k11259557




            251k11259557












            • hrrymc, thanks for your reply. You are speaking over my head. Can I cut and paste that into a macro and try it after changing the range to suit my needs?
              – Paul Y
              Dec 6 at 3:43










            • It should probably work. I recommend studying the subject : VBA is actually not very complicated, except for some ugly syntax. Take a look at the excel-easy tutorials, especially at "Create a Macro" and "Events". There are lots of other posts available on Internet, so you may search for specific questions, or if not found then come back to our site.
              – harrymc
              Dec 6 at 7:31


















            • hrrymc, thanks for your reply. You are speaking over my head. Can I cut and paste that into a macro and try it after changing the range to suit my needs?
              – Paul Y
              Dec 6 at 3:43










            • It should probably work. I recommend studying the subject : VBA is actually not very complicated, except for some ugly syntax. Take a look at the excel-easy tutorials, especially at "Create a Macro" and "Events". There are lots of other posts available on Internet, so you may search for specific questions, or if not found then come back to our site.
              – harrymc
              Dec 6 at 7:31
















            hrrymc, thanks for your reply. You are speaking over my head. Can I cut and paste that into a macro and try it after changing the range to suit my needs?
            – Paul Y
            Dec 6 at 3:43




            hrrymc, thanks for your reply. You are speaking over my head. Can I cut and paste that into a macro and try it after changing the range to suit my needs?
            – Paul Y
            Dec 6 at 3:43












            It should probably work. I recommend studying the subject : VBA is actually not very complicated, except for some ugly syntax. Take a look at the excel-easy tutorials, especially at "Create a Macro" and "Events". There are lots of other posts available on Internet, so you may search for specific questions, or if not found then come back to our site.
            – harrymc
            Dec 6 at 7:31




            It should probably work. I recommend studying the subject : VBA is actually not very complicated, except for some ugly syntax. Take a look at the excel-easy tutorials, especially at "Create a Macro" and "Events". There are lots of other posts available on Internet, so you may search for specific questions, or if not found then come back to our site.
            – harrymc
            Dec 6 at 7:31


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1379886%2fcan-i-use-a-macro-to-protect-a-cell-in-an-excel-spreadsheet-with-a-password%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Paul Cézanne

            UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

            Angular material date-picker (MatDatepicker) auto completes the date on focus out