VBA Needed to Protect Individual Excel Cells

1

124McNaughton

I am trying to create an approval button for my manager that will show the date of the approval and his name along with protecting the cells so they cannot be changed. He would also like the protected cells to be password protected. So far I have a short VBA program that will enter his name and the date he approved the work. I am stuck on the protection aspect of the program, the best that I can do is protect the entire work sheet not the individual cell with a password. I have included the VBA program that I have developed so far.
Any help would be greatly appreciated.

Private Sub ApprovelButton1_Click()
With ActiveSheet
.Unprotect
.Cells(7, 5) = Date
.Cells(7, 6) = "John Doe"
.Protect
End With
End Sub


Thanks in Advanced. :)
 
M

michaelrm

try this

Sub ProtectTheSheet()
Cells.Locked = False
Range("A3:A12,D3:E12,J1:R13,W18").Locked = True
ActiveSheet.protect
End Sub
 
H

Hodgepodge

Assign this macro to your button.

Code:
Sub Rectangle2_Click()
    With ActiveSheet
        .Unprotect Password:="Banana2000"
        .Cells(7, 5) = Date
        .Cells(7, 6) = "John Doe"
        .Cells.Locked = False
        .Range("E7:F7").Locked = True
        .Protect Password:="Banana2000"
    End With
End Sub

See the attachment for an example. I wouldn't normally use "Range" & "Cells" in the same code. I just put it in there the different methods in case others feel more comfortable with one method or the other.
 

Attachments

  • Protect Cells Research.xlsm
    18.4 KB · Views: 200
Top Bottom