vba prevent Range value and formula from change and deleting on unprotected.

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
624
Office Version
  1. 2016
Platform
  1. Windows
VBA or Data Validation to prevent range (A58:BK98) formula and value from being changed and deleted even if sheet is unprotected. if user attempt to error message to refer to Employee List tab to make changes

any suggestion greatly appreciated
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Place in SHEET code window
(do NOT put in a module like Module1)
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Const rng = "A56:BK98"
    If Not Intersect(Selection, Range(rng)) Is Nothing Then
        Application.EnableEvents = False
        MsgBox "Refer Employee List Tab - cannot amend " & rng
        Range("A55").Activate
        Application.EnableEvents = True
    End If
End Sub

error message to refer to Employee List tab to make changes
Suggestion
The above code prevents the user selecting those cells
Instead of Range("A55").Activate , VBA could ask for a password to allow "authorised" user to make changes
 
Upvote 0
Thanks Yongle.

how would I combine that code and if i also have the below code together

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Target.Address = "$A$2" Then
    ActiveWindow.Zoom = 140
  Else
    ActiveWindow.Zoom = 60
  End If
End Sub
 
Upvote 0
Try ...

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Const rng = "A56:BK98"
    ActiveWindow.Zoom = 60
    If Target.Address = "$A$2" Then ActiveWindow.Zoom = 140
    If Not Intersect(Selection, Range(rng)) Is Nothing Then
        Application.EnableEvents = False
        MsgBox "Refer Employee List Tab - cannot amend " & rng
        Range("A55").Activate
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,690
Members
449,092
Latest member
snoom82

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