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
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