Lock cell from editing if a cell in another sheet has a value

GamerNeelie

New Member
Joined
May 21, 2022
Messages
25
Office Version
  1. 2013
Platform
  1. Windows
I have a forecasting table for sales over a 4 week period

FC1.png


Once the sales figures have been recorded and saved on another worksheet the box on the forecast turns yellow to show them sales have been processed (Value is greater than 0)

I need to be able to lock this cell so the user cant go back and edit the forecast for a previous day to give them better forecasting accuracy (Cheating :mad:)

The table is on "Home Page" or "Sheet2" and week 1 range is "J11:P11" [Sunday to Saturday Horizontal]

The linked table that I am recording the actual sales is on "Week1" or "Sheet7" Ranges "C6:C12" [Sunday to Saturday Vertical]

How can I lock Cell "J11" on Home Page if the value in cell "C6" on Sheet 7 is greater than 0?

Thanks.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
You could put this in the worksheet code for shee2 which prevents the user from selecting J11, which makes it difficult to change it. ( if you disable macros it won't work!!)
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("J11:J11")) Is Nothing Then
   If Worksheets("Sheet7").Range("C6") > 0 Then
   Range("J12").Select
   End If
End If

End Sub
 
Upvote 0
Solution
You could put this in the worksheet code for shee2 which prevents the user from selecting J11, which makes it difficult to change it. ( if you disable macros it won't work!!)
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("J11:J11")) Is Nothing Then
   If Worksheets("Sheet7").Range("C6") > 0 Then
   Range("J12").Select
   End If
End If

End Sub
Getting a debug error on "If Worksheets("Sheet7").Range("C6") > 0 Then"
 
Upvote 0
Check your spelling of "sheet7" the code works perfectly well on my machine, what is the error you are getting. What have you got in C6 on Sheet 7
 
Upvote 0
Check your spelling of "sheet7" the code works perfectly well on my machine, what is the error you are getting. What have you got in C6 on Sheet 7
C6 on Sheet 7 is an empty cell until a number is saved in that cell

I copied and pasted the code from the code you posted

FC1.png
 
Upvote 0
That means you do NOT have a sheet called "Sheet7" you must put the correct name, is it "sheet 7" or "Sheet7" or "Sheet 7"
 
Upvote 0
That means you do NOT have a sheet called "Sheet7" you must put the correct name, is it "sheet 7" or "Sheet7" or "Sheet 7"
Ok I got it working, the sheet isn't called "sheet7" its called "week1"
sheet 7 is the name on the sheet list on VBA editor "Sheet7 (Week1)

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("J11:J11")) Is Nothing Then
   If Worksheets("Week1").Range("C6") > 0 Then
   Range("J12").Select
   End If
End If

End Sub

Thank you so much. Been a headache trying to figure that out
 
Upvote 0
So that function works fine for Cell J11

When i tried to replicate that for the next cell on the list (K11) and it doesn't work?

VBA Code:
'Sunday Week1
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("J11:J11")) Is Nothing Then
   If Worksheets("Week1").Range("C6") > 0 Then
   Range("J12").Select
   End If
End If

End Sub
'Monday Week1
Private Sub Worksheet_SelectionChange2(ByVal Target As Range)
If Not Intersect(Target, Range("K11:K11")) Is Nothing Then
   If Worksheets("Week1").Range("C7") > 0 Then
   Range("K12").Select
   End If
End If

End Sub

where am I going wrong?

I had to change the sub name to "Worksheet_SelectionChange2" as it was giving me an Ambiguous name detected error?
 
Upvote 0
Ok after some playing about i released i need to have them all in the same sub


VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("J11:J11")) Is Nothing Then
   If Worksheets("Week1").Range("C6") > 0 Then
   Range("J12").Select
   End If
End If

If Not Intersect(Target, Range("K11:K11")) Is Nothing Then
   If Worksheets("Week1").Range("C7") > 0 Then
   Range("K12").Select
   End If
End If

End Sub
 
Upvote 0
Thank you offthelip for your help. been trying multiple ways to get that working for a while now.

so happy I signed up to this forum. so many helpful people full of knowledge :)
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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