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

Printing a List of AutoCorrect Entries

Want a printed record of the AutoCorrect entries you've created in Word? There is no built-in way to do it, but you can use ...

Discover More

Locking the Position of Tools

Don't want your toolbar tools to move around on you? You might think you are out of luck, but here is a way you can make sure ...

Discover More

Removing a Directory

Macros allow you to perform all sorts of file-related operations. One such operation allows you to delete a directory. This ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

MORE EXCELTIPS (RIBBON)

Saving a Workbook Using Passwords

If you want to protect your workbook so that others cannot open or change the information it contains, an easy way to ...

Discover More

Always Opening a Workbook that is Editable

When you send a workbook to a coworker, it can be bothersome if that person has problems using what you created. There is a ...

Discover More

Protecting an Entire Folder of Workbooks

Want to protect the Excel information stored in a particular folder on your system? There are a number of ways you can ...

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 for this tip:

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 seven minus 6?

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.


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.

Links and Sharing
Share