comment based on cell value in protected sheet

anilkut

New Member
Joined
Jul 9, 2016
Messages
9
I used following vba for comment based on cell value, but when sheet is protected its not working (message .. Run time error '91': prompting for debug)

Sub addCommnent()
''that cell is A1
Dim commentTxt As String, commentRng As Range
Set commentRng = Range("B4")
commentTxt = Range("M15").Value
On Error Resume Next

With commentRng
.Comment.Delete
.AddComment commentTxt

End With
End Sub
Sub addCommtent()
''that cell is A2
Dim commentTxt1 As String, commentRng1 As Range
Set commentRng1 = Range("B5")
commentTxt1 = Range("N15").Value
On Error Resume Next

With commentRng1
.Comment.Delete
.AddComment commentTxt1

End With
End Sub

Private Sub Worksheet_Calculate()
If Range("B4").Comment.Text <> Range("M15").Value Then addCommnent
If Range("B5").Comment.Text <> Range("N15").Value Then addCommtent
End Sub


please guide where I am wrong
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Check what is protected when you protect the worksheet.
You can also unprotect it when the macro runs and protect it again after completion

When protecting a worksheet using a macro you can add the parameter UserInterFaceOnly:=True, this will allow to modify when using VBA even if the sheet is protected but not the suer
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,282
Members
452,902
Latest member
Knuddeluff

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