Results 1 to 7 of 7

Locking edited cells

Threaded View

ANDREWA Locking edited cells 08-12-2009, 08:10 AM
royUK re: Locking edited cells 08-12-2009, 08:20 AM
ANDREWA Re: Locking edited cells 08-18-2009, 05:03 AM
Phil_V Re: Locking edited cells 08-18-2009, 06:15 AM
ANDREWA Re: Locking edited cells 08-19-2009, 05:53 AM
Phil_V Re: Locking edited cells 08-19-2009, 06:06 AM
ANDREWA Re: Locking edited cells 08-27-2009, 03:47 AM
  1. #1
    Registered User
    Join Date
    08-12-2009
    Location
    Cardiff, Wales
    MS-Off Ver
    Excel 2007
    Posts
    53

    Locking edited cells

    I hope someone can help, my VBA is some what limited, its been a long time.
    The code I have put together is working ok apart from a few small problems.
    Im hoping someone can look at my code and tell me where i'm going wrong.

    If I explain what it is ment to do first, then this should make things easier.
    Basically, when a user inputs any text in to a cell the cell automatically creates a comment of when, what and who by, and then locks the cell preventing further editing. This all works fine. So whats the problem? Users have started using copy and paste when multiple entries are required. If a single protected cell is copied to another single cell then the code still works fine, but if a single cell is copied and pasted into multiple cells then the value is copied to the cells, but the multiple cells do not lock? If the value in these cells is edited further then they lock.
    So basically I need the code to work when multiple cells have been pasted, rather than just one cell being edited.

    Hope someone is able to help?

    Here is the code:-
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Cells.Count > 1 Then Exit Sub
    
    If Intersect(Target, Range("A4:A1000,B4:B1000,C4:C1000,D4:D1000,E4:E1000,F4:F1000,G4:G1000,H4:H1000,I4:I1000,J4:J1000,K4:K1000")) Is Nothing Then Exit Sub
    
    If Target.Value <> "" Then
            ActiveSheet.Unprotect Password:="AA"
    Dim NewText As String
    Dim NewVal As Variant
    Dim OldText As String
    Dim OldVal As Variant
    
    Application.EnableEvents = False
    NewVal = Target.Value
    Application.Undo
    OldVal = ActiveCell.Value
    ActiveCell = NewVal
    Application.EnableEvents = True
    
    NewText = "On " & Now() & " cell changed from " & OldVal _
    & " to " & NewVal & " by " & Environ("UserName")
    
    If ActiveCell.Comment Is Nothing Then
    ActiveCell.AddComment
    End If
    
    
    With ActiveCell.Comment
    .Shape.TextFrame.AutoSize = True
    OldText = .Text & vbLf
    .Text Text:=OldText & NewText
    End With
    
    
            Target.Locked = True
            ActiveSheet.Protect Password:="AA"
        End If
        
    End Sub
    Last edited by royUK; 08-12-2009 at 08:20 AM. Reason: add code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1