customize excel error message

excel_nubie

New Member
Joined
Jan 19, 2009
Messages
9
I got the below code from Mr. Excel to protect a cell with data from being overwritten. I also had to highlight all cells & select format, cell, protection & uncheck locked. It works beautifully. I'm so psyched!! The next step is to customize the error message. Can someone help me with this? Many thanks!!

Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect "password"
Target.Locked = True
ActiveSheet.Protect "password"
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
oh, sorry about not being more clear. When you click on a cell containing data, excel displays a standard msg: "The cell or chart you are trying to change is protected and therefore read only. To modify a protected cell or chart, first remove protection using the Unprotect sheet command...". I'd like to change the text of this message, or stop it from displaying and display my own message. thanks.
 
Upvote 0
You cannot customize this error message either ways. However, you can stop it from being displayed provided you let us know what are you trying to do, how is your data layout on the worksheet, what cell / cells do you want the user to modify on a protected worksheet ?
 
Upvote 0
If there is data in a cell, a person should NOT be able to modify the cell contents.

Can i suppress excel's error, and display my own message?
 
Upvote 0
This only displays a message, it does not stop the edit!

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Sheet module code only, like: Sheet1!

If Target.Value <> "" Then
MsgBox "You can only add information to BLANK cells!" & vbLf & _
"Any cell with a value cannot be edited!", _
vbCritical + vbOKOnly, _
"Edit Error!"
Else
End If
End Sub
 
Upvote 0
Thanks for the reply. i copied & pasted the code as shown below. I also tried moving it to the top of the code, and again after the first line. Only excel's standard msg displays. Can you help out? thanks very much.

Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect "password"
Target.Locked = True
ActiveSheet.Protect "password"
If Target.Value <> "" Then
MsgBox "You can only add information to BLANK cells!" & vbLf & _
"Any cell with a value cannot be edited!", _
vbCritical + vbOKOnly, _
"Edit Error!"
Else
End If
End Sub
<!-- / message -->
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,854
Members
449,096
Latest member
Erald

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