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

Limiting Who Can Delete Data

by Allen Wyatt
(last updated February 6, 2017)

6

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.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11598) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel 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

Compound List Formatting

Word can help you do quite a bit of complex formatting to your lists, both bulleted and numbered. Using the steps outlined in ...

Discover More

Going to the Corners of a Selected Range

When you select a range of cells (particularly if it is a large range of cells), you may not be quite sure if you've selected ...

Discover More

Protecting a Worksheet's Format

You can protect various parts of your worksheets by using the tools built into Excel. One thing you can protect is the format ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Removing Protection from a Protected Workbook

Excel provides built-in capabilities to protect your workbook files. If you apply these capabilities, it is possible that at ...

Discover More

Using Strong Workbook Protection

Need to protect the data in your workbook so that others can't get at it? Here are some ideas on how you can approach the ...

Discover More

Protecting an Entire Workbook

Want to stop other people from making unauthorized changes to your workbook? Excel provides a way that you can protect the ...

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. 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 five less than 5?

2014-10-30 10:20:50

Bigger Don

@ balthamossa2b

The answer is "No", but I cheated and looked it up. :)

If you need to know how to get the same as Environ() on a Mac, it's readily available via a Google search. I would share it here but I'm not into plagiarism and don't want to make it look like I'm here promoting other sites.


2014-10-29 18:46:16

balthamossa2b

@Don

My bad, I was thinking of Environ but said Application. For some reason I had in mind that some Application variables let you access the Windows account, but obviously now I realize it doesn't.

In the company where I used this everyone had an Office name by default, so both approaches are equivalent. But not usually.

Bonus question: does Environ stuff work in Mac?


2014-10-29 14:56:44

Julio Alfaro

I would like to have some help, converting Julian date to regular date


2014-10-29 09:06:07

Bigger Don

@balthamossa2b

First, and this is just being picky, I think you meant "Application.UserName". (Happens to me all the time when I type what I think I know.)

Second, Application.UserName returns whatever the user puts into Excel as there user name. I have users whose Application.UserName are "d" and "g" because they simply accept the default.

For that reason I use Environ("UserName"). This returns the user name associated with the computer login, something that I find much more reliable.


2014-10-28 10:13:32

Shandor

Tricks for smartypants who tried to bypass protection--I love it!


2014-10-28 08:34:26

balthamossa2b

An easier alternative is to use the Application.User value to see who is using the file.

I remember creating a macro that would delete all the data in the workbook if the User wasn't approved. With a couple tricks thrown in for the smartpants who tried to bypass the protection.

Fun times.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.