Lock Script misses first Range

SeliM

Board Regular
Joined
Aug 10, 2023
Messages
57
Office Version
  1. 365
Platform
  1. Windows
Hello
Thanks for reading my enquiry.
I'm putting a Sudoku puzzle generator together for grandkids and have a functioning model nearly complete.

I have script that locks a generated puzzle and "locks" cells that are not empty as in "".
The range covers all 9 games, ( of 9 rows and 9 columns) - $B3:$J$11

Script works for the eight rows but does not lock the filled cells on row 3.
Any advice welcomed.

Script below:
Sub LocktheGame()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Sudoku")
For Each Rng In ActiveSheet.Range("$B$3:$J$11")
'To test if cell is empty
If Rng.Value = "" Then
'If empty lock cell
Rng.Locked = False
Else
'If cell not emty
Rng.Locked = True

End If

Next Rng

Worksheets("Sudoku").Activate
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells

ActiveSheet.Protect "pass"
screenupdate = True
Sheets("Givens Management").Select
ActiveWindow.SelectedSheets.Visible = False
Range("B3").Select

End Sub

Many thanks
Mel
 
Well that is strange because I cannot change it. I get this
1732721639433.png

If you have a solution that's great. I might have just picked a different cell to select - one outside of the grid; perhaps B2
Merry Christmas to you also.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,272
Messages
6,177,630
Members
452,786
Latest member
k3calloway

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