Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Limiting Who Can Delete Data.

Limiting Who Can Delete Data

Written by Allen Wyatt (last updated July 5, 2022)
This tip applies to Excel 97, 2000, 2002, and 2003


4

Jim has a workbook that is used by multiple people in his company. He wonders if there is a way to allow everyone to add data to a group of cells, yet restrict who can delete the data from the cells. He has a group of about 50 that he wants to be able to add data, but he wants to give the delete capability to just 2 individuals.

There are any number of macro-based solutions you can try. Essentially, you need a macro to detect when information has been deleted and then check to see if the person deleting the information has permission to do so. The following is just one possible approach to the issue:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim sPassCheck As String
    Dim rng As Range
    Dim sTemp As String
    Dim sPassword As String

    sPassword = "Password"
    sTemp = "You must enter the password to delete data"

    'Use to set a single cell if more than one cell is
    'in the target range
    If Target.Count > 1 Then
        Set rng = Target.Cells(1, 1)
    Else
        Set rng = Target
    End If

    If rng.Value = "" Then
        sPassCheck = InputBox(sTemp, "Delete check!")
        Application.EnableEvents = False
        If sPassCheck <> sPassword Then Application.Undo
    End If

    Application.EnableEvents = True
End Sub

The macro, which is actually an event handler triggered whenever something in the worksheet is changed, checks to see if the information in a cell (or top-left cell in a range) was deleted. If so, then the user is asked for a password. If the person doesn't have the password, then the Undo method is invoked to "undo" the person's deletion. (You'll want to change the password, assigned to the sPassword variable) to the actual password you want people to use.)

Another option is to use an Excel add-in that can take care of the security issues for you. Some subscribers suggest using A-Tools, which comes in either a free or pro (paid) edition. You can find more information about this add-in here:

http://www.atoolspro.com/

A-Tools, among other things, apparently allows you to apply various security features to Excel data that resides on a network. (Chances are good that Jim is sharing his workbook on a network, as it is used by many people in his company.)

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11597) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Limiting Who Can Delete Data.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Converting Numbers to Strings

VBA is great at working with both strings and numbers. At some point, you may have a number you need to convert to a ...

Discover More

Automatically Breaking Text

Want to convert the text in a cell so that it wraps after every word? You could edit the cell and press Alt+Enter after ...

Discover More

Summing Based on Part of a Control Cell

When analyzing data, you may have a need to calculate a sum based on just part of a particular cell. This tip examines ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Losing Data in a Shared Workbook

When you create a shared workbook, you run the risk of losing some of the data in that workbook. Here's a discussion ...

Discover More

Unwanted Read-Only Workbook Status

Once a workbook assumes a "read-only" status, it can be a real pain to get that status removed. This tip explains why and ...

Discover More

Working With Multiple Workbooks

Need to do work in more than one workbook at a time? For many, this ability is a necessity. Excel allows you to easily ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 1 + 1?

2019-01-30 03:22:43

Barry

I always thought the Undo stack was cleared when a macro was run.


2019-01-29 11:32:53

Lee

Same thing for me...Doesn't work.


2018-07-02 13:11:06

Sudhir

I tried running this code but could not get it to work. I am not sure what i did wrong here. In the excel, i opened the developer tab, then in the Code box, i opened Visual basic, Clicked ThisWorkbook on the left hand side panel and pasted this code. Saved the file and tried to observe if i could delete the info. It allowed deleting so not sure what's happening here.


2018-06-15 11:42:03

Luke

Fantastic, except that the range doesn't work. Set the range to (A1, G251) but the password request appears regardless of which cell I delete from. (Also used ("A1:G251") also to no avail.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.