How to get error only when edited or when double clicked.

DemonX

New Member
Joined
Jan 17, 2021
Messages
20
Office Version
  1. 2019
Platform
  1. Windows
Following code was provided by a good samaritan in this forum, and while I do testing, I found an error which I kindly need further assistance.

Below code will give an error when the excel cell is double-clicked when it is locked in format. Now the issue is, I observed when the cell is just selected ( only one click on cell), users are still able to edit ( enter values ).

I can not use Protect sheet functionality since it will ignore customize error :(.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

If Target.Locked Then
MsgBox "Stop!" & vbNewLine & vbNewLine & "Please Update only the YELLOW cells.", vbCritical, "STOP!"
Cancel = True
End If
End Sub

Could we get an error when double-clicked or when any value tried to enter? At least the latter would be great.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I can not use Protect sheet functionality since it will ignore customize error :(.
It would be better to protect the sheet and sacrifice the custom message. There a far too many ways that using vba in an attempt to protect an unprotected sheet can fail.

Your existing code doesn't work if you click the OK button then start typing.
 
Upvote 0
I agree with Jason.
If you have the entire sheet locked, but unlock cells A1:A3 then enter any value into those 3 cells & then enter something in A4 it will unlock itself.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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