Require password to delete entries

chinaboy

New Member
Joined
Jun 28, 2010
Messages
27
Good morning... I have a piece of code that should require a password prompt when a user attempts to delete data after entering it. But it doesn't seem to work. Ver new to this vba stuff. There is a range of cells I would like to restrict. Can you someone offer some suggestions on correcting it a better method to meeting my objective. The workbook is shared so trying to prevent other users from deleting someone on entry and to restrict deletion only to those that have the password.

Thanks in advance.

Code:
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 = "Only members of the Management Team is authorized to delete an entry."
    '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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
What precisely does "doesn't seem to work" mean?

Is that code in the correct worksheet code module?
 
Upvote 0
The code is currently in the ThisWorkbook in the Worksheet_Change.

Nothing happens when I try to delete existing data.
 
Upvote 0
That code needs to be in the worksheet code module of the worksheet you want it to work on. It will not trigger from within the ThisWorkbook module.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top