Prevent update/entries on cell range based on sheet/tab name?

FGaxha

Board Regular
Joined
Jan 10, 2023
Messages
221
Office Version
  1. 365
Platform
  1. Windows
Hi,
VBA Code: How to prevent update/entries on cell range "C33 :F52" if Tab Name is "MASTER" else ok
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Why do you need a vba code? Why not just manually lock those cells and protect the sheet?
 
Upvote 0
Hi ,
I am looking for: Prevent updated on cell range if SHEET NAME IS "MASTER"
thanks
 
Upvote 0
@FGaxha
try this
copy and paste in MASTER sheet module
if the sheet name is MASTER will not update ,if change sheet name will update
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Cells.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("C33:F52")) Is Nothing Then
    If ActiveSheet.Name = "MASTER" Then
        cng = Target.Value
        Application.Undo
        Target.Value = Target.Value
        Else
    End If
    End If
Application.EnableEvents = True
End Sub
 
Upvote 1
@Maklil You need to change the placement of this line Application.EnableEvents = False otherwise you are going to permanently disable events.
 
Upvote 0
Prevent updated on cell range if SHEET NAME IS "MASTER"
As has already been suggested, why not just protect that sheet, so that people cannot change the cells?
 
Upvote 0
@FGaxha
move first line after third line to become
VBA Code:
If Target.Cells.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("C33:F52")) Is Nothing Then
Application.EnableEvents = False
 
Upvote 1
Guys, Thank you so much, it works perfectly.
I was using :
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255) to get Tab Name to Cell A1 and then
Custom Data Validation =$A$1 <>"Master".

VBA: work great
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C33:F52")) Is Nothing Then
Application.EnableEvents = False
cng = Target.Value
Application.Undo
Target.Value = Target.Value
Else
End If
Application.EnableEvents = True
End Sub
 
Upvote 0
I did,
This work great:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C33:F52")) Is Nothing Then
Application.EnableEvents = False
cng = Target.Value
Application.Undo
Target.Value = Target.Value
Else
End If
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

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