marreco
01-11-2012, 02:40 AM
Good morning people!
The following code prevents the common user to change any value in the cells.
But I need the administrator of the spreadsheet has the ability to change the data, I have a UserForm with a TextBox.
How do I adapt the code below and when the administrator of the worksheet, have the need to change the worksheet data. call the UserForm code so that it can do this with password in the TextBox?
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:F1000")) Is Nothing Then
NewValue = Target.Value
Application.EnableEvents = False
Application.Undo
OldValue = Target.Value
If OldValue = "" Then
Target.Value = NewValue
'ElseIf 'Before there was InputBox Then
Target.Value = NewValue
Else: MsgBox "Você não pode alterar o conteudo da celula.", 16, "Células Bloqueadas"
Target.Value = OldValue
End If
Application.EnableEvents = True
End If
End Sub
The following code prevents the common user to change any value in the cells.
But I need the administrator of the spreadsheet has the ability to change the data, I have a UserForm with a TextBox.
How do I adapt the code below and when the administrator of the worksheet, have the need to change the worksheet data. call the UserForm code so that it can do this with password in the TextBox?
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:F1000")) Is Nothing Then
NewValue = Target.Value
Application.EnableEvents = False
Application.Undo
OldValue = Target.Value
If OldValue = "" Then
Target.Value = NewValue
'ElseIf 'Before there was InputBox Then
Target.Value = NewValue
Else: MsgBox "Você não pode alterar o conteudo da celula.", 16, "Células Bloqueadas"
Target.Value = OldValue
End If
Application.EnableEvents = True
End If
End Sub