Hi there,
I have problem with my Sudoku Generator. It's about the difficulty level.
My macro always returns 39-43 numbers completed.
How to do to increase the difficulty level and the macro returned ≈27 for the intermediate level, ≈21 for the difficult level, and ≈37 for the easy level.
I have problem with my Sudoku Generator. It's about the difficulty level.
My macro always returns 39-43 numbers completed.
How to do to increase the difficulty level and the macro returned ≈27 for the intermediate level, ≈21 for the difficult level, and ≈37 for the easy level.
VBA Code:
Sub CreatPuzzle()
Sheets("sudoku1").Select
Dim num As Integer, LoopCount As Integer
Dim CellRow As Integer, CellCol As Integer
Dim uCell As Integer, Comp As Boolean
Do
Randomize
CellRow = Int((10 - 2 + 1) * Rnd + 2)
CellCol = Int((10 - 2 + 1) * Rnd + 2)
num = Val(Cells(CellRow, CellCol).Value)
If num <> 0 Then
Comp = False
For uCell = 2 To 10
'Rows
If Cells(uCell, CellCol).Value = "" Then
If WorksheetFunction.CountIf(Rows(uCell), num) = 0 And _
WorksheetFunction.CountIf(Range(qRNG(uCell, CellCol)), num) = 0 Then Comp = True
End If
'Columns
If Cells(CellRow, uCell).Value = "" Then
If WorksheetFunction.CountIf(Columns(uCell), num) = 0 And _
WorksheetFunction.CountIf(Range(qRNG(CellRow, uCell)), num) = 0 Then Comp = True
End If
Next uCell
If Comp = False Then
Cells(CellRow, CellCol).Value = ""
End If
End If
LoopCount = LoopCount + 1
If LoopCount > 299 Then Exit Do
Loop
End Sub