r/vba • u/NewAssistance235 • Jul 04 '24
Unsolved Disable Delete Key and display Msgbox
Hello! Hope all of you are doing great! This sounds like a beginner problem but it can’t seem to make it work.
I have been using an excel file to track patient data but somebody keeps deleting formulas. I have two functions here - first to disable right click so user can’t select data and delete it by using right click and the next is disable delete key and trigger a vba message about GDPR and source data integrity. I managed to sort disable right click but I can’t manage to get disable delete key work. I have used the vba code (attached) which forums have talked through.
Could any of you please help? I will be super grateful!
18
u/tbRedd 25 Jul 04 '24
Lol, this is a new one, posting code via video and not even rotated or cropped accurately. 😱 Try selecting the VBA code, use copy, paste into a comment or pastebin or something.
7
Jul 04 '24
[removed] — view removed comment
5
u/DOUBLEBARRELASSFUCK 1 Jul 04 '24
I could understand that if the code couldn't be manually retyped in less than 5 minutes.
1
3
u/Cabanon_Creations Jul 04 '24
Yes. I would also do a bad vertical video shot of my screen to bypass my government cybersecurities
6
u/CondomAds 1 Jul 04 '24
I believe you should learn about locking cells and cells restriction. IMO, it is not something you should use VBA for. Sure, you might be able to remove the "delete key", but then they can just press a random key and it will be deleted anyway.
4
u/lolcrunchy 12 Jul 04 '24
There a lots of ways to remove the contents of a cell without using the Delete key, so you're putting in a lot of work to solve a fraction of the problem.
I recommend using the Workbook_SheetChange event. First, define the protected area as a named range, maybe call it "rng_formulas". Then in the event code, do
Private Sub Workbook_SheetChange(Sh as Object, Target as Range)
If Not Intersect(Target, Range("rng_formulas")) Is Nothing Then
MsgBox "Please do not change formula cells!"
Application.Undo
End If
End Sub2
u/nagure Jul 05 '24
If the matter Is deleted formula i resolved the problem respawning them each time the workbook loads. You can write formula in vba or use a hidden sheet where to keep them up-to-date and have vba Copy and paste in the worksheets
1
u/Lucky-Replacement848 Jul 06 '24
On open,, hmm,, how about a formula that logs user and whats edited
or if its just accident, you can set a macro to set back the formula on the cell
12
u/daishiknyte 7 Jul 04 '24
Why not lock the cells they should not be touching?