PDA

View Full Version : Cells blocked with permission to change



marreco
12-31-2011, 03:37 AM
Hi....


Personally I have 3 users that use a single worksheet.

The users User1 and User2 feeds the sheet named "Master"
User3 analyzes information but if there is something wrong he alone will have the Permissions to change the data in the spreadsheet "Master".
So ...
The code below works perfectly, but I would add an input box to allow only user3 can change the worksheet data "Master".


Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewValue As Variant, OldValue As Variant
If Target.Count > 1 Then Exit Sub
'Say you want to work with the range A1:F100
If Not Intersect(Target, Range("A1:F10")) Is Nothing Then
NewValue = Target.Value
Application.EnableEvents = False
Application.Undo
OldValue = Target.Value
If OldValue <> "" Then
MsgBox "Você não pode alterar o conteudo da celula.", 16, "Células Bloqueadas"
Target.Value = OldValue
Else
Target.Value = NewValue
End If
Application.EnableEvents = True
End If
End Sub

cross-posting
http://www.excelforum.com/excel-programming/807559-cells-blocked-with-permission-to-change.html

Can anyone help me?
Thank you!

marreco
01-02-2012, 02:22 PM
Hello folks, I'd love your help.
I know we have teachers excel in this forum, please help me ..... thanks!

omp001
01-02-2012, 05:07 PM
Hi. Try this:
replace these lines
If OldValue <> "" Then
MsgBox "Você não pode alterar o conteudo da celula.", 16, "Células Bloqueadas"
Target.Value = OldValue
Else
Target.Value = NewValue

with these ones
If OldValue = "" Then
Target.Value = NewValue
ElseIf InputBox("enter password") = "pwd" Then
Target.Value = NewValue
Else: MsgBox "Você não pode alterar o conteudo da celula.", 16, "Células Bloqueadas"
Target.Value = OldValue

don't forget to protect your VBA project to avoid that one could see the 'pwd'

marreco
01-03-2012, 07:57 AM
My great friend.:thumb
you helped me solve a big problem.:clap:
I found the one to help me, I am eternally grateful.

the level you are a master excel thanks!:bow:

Thank you very much !!!!!!!!!!:beerchug: