Consulting

Results 1 to 4 of 4

Thread: Cells blocked with permission to change

  1. #1
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location

    Cells blocked with permission to change

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

    [VBA]
    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[/VBA]

    cross-posting
    http://www.excelforum.com/excel-prog...to-change.html

    Can anyone help me?
    Thank you!

  2. #2
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location
    Hello folks, I'd love your help.
    I know we have teachers excel in this forum, please help me ..... thanks!

  3. #3
    VBAX Regular
    Joined
    Aug 2011
    Posts
    87
    Location
    Hi. Try this:
    replace these lines
    [vba] If OldValue <> "" Then
    MsgBox "Você não pode alterar o conteudo da celula.", 16, "Células Bloqueadas"
    Target.Value = OldValue
    Else
    Target.Value = NewValue
    [/vba]
    with these ones
    [vba] 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
    [/vba]
    don't forget to protect your VBA project to avoid that one could see the 'pwd'
    Regards
    Osvaldo

  4. #4
    VBAX Tutor
    Joined
    Jan 2011
    Posts
    272
    Location

    SOLVED

    My great friend.
    you helped me solve a big problem.
    I found the one to help me, I am eternally grateful.

    the level you are a master excel thanks!

    Thank you very much !!!!!!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •