Results 1 to 3 of 3

VBA to unlock cells, run macro then re-lock them

Threaded View

  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    50

    VBA to unlock cells, run macro then re-lock them

    Hi
    I have the following code in a worksheet of which Ive locked columns AA & AB, then password protected the worksheet. However when I run my code I keep getting a
    run-time error '1004': unable to set the locked property of the range class error
    .
    Can anybody help please....I am assuming I need some code to unlock the sheet with the password before unlocking and then re-locking the cells??

    Private Sub Worksheet_Change(ByVal Target As Range)
        
        If Target.Column = 1 Or Target.Column = 2 Or Target.Column = 3 Or _
        Target.Column = 4 Or Target.Column = 5 Or Target.Column = 6 Or _
        Target.Column = 7 Or Target.Column = 8 Or Target.Column = 9 Or _
        Target.Column = 10 Or Target.Column = 11 Or Target.Column = 12 Or _
        Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15 Or _
        Target.Column = 16 Or Target.Column = 17 Or Target.Column = 18 Then
            
            Cells(Target.Row, 27).Locked = False
            Cells(Target.Row, 28).Locked = False
            Cells(Target.Row, 27).Value = Now
            Cells(Target.Row, 28).Value = Environ("Username")
            Cells(Target.Row, 27).Locked = True
            Cells(Target.Row, 28).Locked = True
                    
            End If
            
    End Sub
    Thanks in advance

    Jen
    Last edited by arlu1201; 03-05-2013 at 03:09 AM.

Thread Information

Users Browsing this Thread

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

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