bottom
Great ExcelTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > ExcelTips Home > Workbooks > Protecting Workbooks > Automatically Protecting After Input

Automatically Protecting After Input

Summary: Do you want user-entered data to be immediately protected so that it cannot be changed? This can be done relatively easily using a simple macro. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)

Excel offers protection for your worksheets, meaning that you can protect the contents of cells so they cannot be changed. Exactly how you use this protection has been discussed in other issues of ExcelTips. What if you want to allow cells to be edited, but you want them to become protected right after someone enters information in the cell? For instance, you have cells in which a user could enter information, but once entered, you don't want them to have the ability to change the information they entered.

There is no inherent ability in Excel to protect your input, but you can create the ability through the use of a macro. The following macro is an example of how you can do this:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MyRange As Range

    Set MyRange = Intersect(Range("A1:D100"), Target)
    If Not MyRange Is Nothing Then
        Sheets("Sheet1").Unprotect password:="hello"
        MyRange.Locked = True
        Sheets("Sheet1").Protect password:="hello"
    End If
End Sub

This macro assumes that the worksheet has already been protected, and that all the cells where you want input to be possible are unlocked. What it does is check to see if the input was done in the proper range of cells, in this case somewhere in the range of A1:D100. If it was, then the worksheet is unprotected, the cell in which information was just entered is locked, and the worksheet is again protected.

If you are using this approach in your own workbook, you will need to modify the potential input range, and you will want to change the password used to unprotected and protect the worksheet.

Tip #2034 applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003 | 2007


Make Home Buying Less Stressful! Why face the annual problems associated with Christmas debt? Learn how to avoid that debt and conquer your financial challenges.
 
Check out Buying a Home Checklist today!

Helpful Links

Ask an Excel Question
Make a Comment

Tips.Net Home

ExcelTips FAQ
ExcelTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
ExcelTips Site

 

Great Info!

Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)