Need cells to lock until a comment is added in the comment cell then unprotect sheet

vrowland

New Member
Joined
Nov 29, 2017
Messages
2
I am new to visual basic and need some help with some coding. I have a excel template that has an plan end date and actual end date (2 separate columns) if my actual end date is greater then my plan end date, I need a message box to explain they need to write a comment. If there is no comment the worksheet needs to lock down so they can not do anything. Once the comment is added the worksheet will unlock. I am getting errors and it doesn't look like it is working. Can anyone help me with my code.

Sub CommentNeeded()

Dim date1 As Date
Dim date2 As Date

ActiveSheet.Unprotect ("me")

If date1> date2 Then
Msgbox "You must input a comment to explain the delay. Sheet will be locked until comment is added"

Else
Worksheets("Hardware").Range("J7:J32").Cells.Locked = False
Worksheets("Hardware").Protect

End If

If date1=date2 Then
Worksheets("Hardware"). Unprotect
End If

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,833
Messages
6,127,156
Members
449,367
Latest member
w88mp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top