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

DemonX

New Member
Joined
Jan 17, 2021
Messages
19
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.
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
12,497
Office Version
  1. 365
Platform
  1. Windows
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,805
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,128,165
Messages
5,629,068
Members
416,363
Latest member
zaveedd

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
Top