Be the first user to complete this post

  • 0
Add to List

VBA-Excel: SUDOKU Solver

Download Link : SUDOKU Solver

Steps:

  • Open a new WorkBook
  • Create a SUDOKU template
  • Create a Button
  • Copy Paste the Complete Code
  • Press the button till the SUDOKU is solved.

Note: This Code works only for easy and medium level SUDOKU problems

After Creating the SUDOKU template you page should look like this:

NOTE: Make sure you create the template in correct cells else you will have to change the code

Create a SUDOKU template

SUDOKU SOLVER-1
SUDOKU SOLVER-1


Create a Button

To know how to add a button Click here (Assign-a-macro-to-a-button)

Copy Paste the Complete Code

Press Alt+F11 and Copy paste the code below


Dim mainWorkBook As Workbook
Dim arrMatrix(1 To 9, 1 To 3, 1 To 3)
Dim arrOptions(9)
Dim arrAlreadyUpdated()
Dim blnHaveSomethingToFill

Sub Sumit()
Set mainWorkBook = ActiveWorkbook
Call FnGetValues

blnHaveSomethingToFill = False
For i = 1 To 9
StrA = ""
'intAUCounter = 0
'ReDim Preserve arrAlreadyUpdated(0)
For j = 1 To 3
For k = 1 To 3
'MsgBox i & " " & j & "      " & arrMatrix(i, j)
If arrMatrix(i, j, k) = "" Then

Call FnFillOptionsArray
Call FnCalculate(i, j, k)
intCounterO = 0
'StrA = ""
For p = 0 To 8
StrA = StrA & "  " & arrOptions(p)
If arrOptions(p) = 0 Then
intCounterO = intCounterO + 1
End If
Next
If i = 4 Then
'MsgBox i & j & k & "     " & StrA
End If

'intAUCounter = intAUCounter + 1
'ReDim Preserve arrAlreadyUpdated(intAUCounter)
'arrAlreadyUpdated(intAUCounter - 1) = i & " " & j & " " & k
'MsgBox arrAlreadyUpdated(intAUCounter - 1) & " Entered"

If intCounterO = 8 Then
'intAUCounter = 0
For p = 0 To 8
If arrOptions(p) <> 0 Then
arrMatrix(i, j, k) = arrOptions(p)
'MsgBox "have"
blnHaveSomethingToFill = True
End If
Next
End If
End If
Next
Next
If blnHaveSomethingToFill = False Then
For a = 1 To 9
StrA = Replace(StrA, " ", "")
strTemp = StrA
If Len(strTemp) - Len(Replace(strTemp, CStr(a), "")) = 1 Then
' MsgBox StrA
intLocation = InStr(1, StrA, CStr(a), 1)
' MsgBox intLocation
intCell = 0
If Int(intLocation / 9) <> (intLocation / 9) Then
intCell = Int(intLocation / 9) + 1
Else
intCell = Int(intLocation / 9)
End If
' MsgBox intCell & " Location"
'arrTemp = Split(arrAlreadyUpdated(intCell - 1), " ")
'intI = CInt(arrTemp(0))
'intJ = CInt(arrTemp(1))
'intK = CInt(arrTemp(2))
' MsgBox intI & intJ & intK
intC = 0
blnFound = False
For j = 1 To 3
For k = 1 To 3
'MsgBox i & " " & j & "      " & arrMatrix(i, j)
If arrMatrix(i, j, k) = "" Then
''MsgBox "411" & arrMatrix(4, 1, 1)
intC = intC + 1
'MsgBox "intC" & intC
'MsgBox i & j & k
If intC = intCell Then
arrMatrix(i, j, k) = a
'Call FnFillValues
' MsgBox i & j & k & "Matched" & "   " & a
blnFound = True
Exit For
End If
End If
Next
If blnFound Then
Exit For
End If
Next
Exit For
StrA = ""
strTemp = ""
End If
Next

End If
Next

ReDim Preserve arrAlreadyUpdated(0)

Call FnFillValues

End Sub

Function FnFillOptionsArray()

arrOptions(0) = 1
arrOptions(1) = 2
arrOptions(2) = 3
arrOptions(3) = 4
arrOptions(4) = 5
arrOptions(5) = 6
arrOptions(6) = 7
arrOptions(7) = 8
arrOptions(8) = 9

End Function

Function FnCalculate(a, b, c)

For j = 1 To 3
For k = 1 To 3
If arrMatrix(a, j, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(a, j, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next

If a = 1 Then
For j = 1 To 3
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 1 To 7 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

If a = 2 Then
For j = 1 To 3
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 2 To 8 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

If a = 3 Then
For j = 1 To 3
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 3 To 9 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

If a = 4 Then
For j = 4 To 6
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 1 To 7 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

If a = 5 Then
For j = 4 To 6
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 2 To 8 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

If a = 6 Then
For j = 4 To 6
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 3 To 9 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

If a = 7 Then
For j = 7 To 9
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 1 To 7 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

If a = 8 Then
For j = 7 To 9
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 2 To 8 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

If a = 9 Then
For j = 7 To 9
For k = 1 To 3
If arrMatrix(j, k, c) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, k, c) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
For j = 3 To 9 Step 3
For k = 1 To 3
If arrMatrix(j, b, k) <> "" Then
For m = 0 To 8
If arrOptions(m) = arrMatrix(j, b, k) Then
arrOptions(m) = 0
End If
Next
End If
Next
Next
End If

End Function

Function FnGetValues()
'intChar = 69
'j = 1
'Set mainWorkBook = ActiveWorkbook
'For k = 1 To 9
'   For m = 69 To 77
'      For k = 1 To 3
'          For i = 1 To 3
'             arrMatrix(k, i, j) = mainWorkBook.Sheets("Sheet1").Range(Chr(m) & i + 4).Value
'        Next
'       j = j + 1
'  Next
'Next
'Next

arrMatrix(1, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("E5").Value
arrMatrix(1, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("E6").Value
arrMatrix(1, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("E7").Value
arrMatrix(2, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("E8").Value
arrMatrix(2, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("E9").Value
arrMatrix(2, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("E10").Value
arrMatrix(3, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("E11").Value
arrMatrix(3, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("E12").Value
arrMatrix(3, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("E13").Value

arrMatrix(1, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("F5").Value
arrMatrix(1, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("F6").Value
arrMatrix(1, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("F7").Value
arrMatrix(2, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("F8").Value
arrMatrix(2, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("F9").Value
arrMatrix(2, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("F10").Value
arrMatrix(3, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("F11").Value
arrMatrix(3, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("F12").Value
arrMatrix(3, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("F13").Value

arrMatrix(1, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("G5").Value
arrMatrix(1, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("G6").Value
arrMatrix(1, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("G7").Value
arrMatrix(2, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("G8").Value
arrMatrix(2, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("G9").Value
arrMatrix(2, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("G10").Value
arrMatrix(3, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("G11").Value
arrMatrix(3, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("G12").Value
arrMatrix(3, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("G13").Value

arrMatrix(4, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("H5").Value
arrMatrix(4, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("H6").Value
arrMatrix(4, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("H7").Value
arrMatrix(5, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("H8").Value
arrMatrix(5, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("H9").Value
arrMatrix(5, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("H10").Value
arrMatrix(6, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("H11").Value
arrMatrix(6, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("H12").Value
arrMatrix(6, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("H13").Value

arrMatrix(4, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("I5").Value
arrMatrix(4, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("I6").Value
arrMatrix(4, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("I7").Value
arrMatrix(5, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("I8").Value
arrMatrix(5, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("I9").Value
arrMatrix(5, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("I10").Value
arrMatrix(6, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("I11").Value
arrMatrix(6, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("I12").Value
arrMatrix(6, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("I13").Value

arrMatrix(4, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("J5").Value
arrMatrix(4, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("J6").Value
arrMatrix(4, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("J7").Value
arrMatrix(5, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("J8").Value
arrMatrix(5, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("J9").Value
arrMatrix(5, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("J10").Value
arrMatrix(6, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("J11").Value
arrMatrix(6, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("J12").Value
arrMatrix(6, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("J13").Value

arrMatrix(7, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("K5").Value
arrMatrix(7, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("K6").Value
arrMatrix(7, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("K7").Value
arrMatrix(8, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("K8").Value
arrMatrix(8, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("K9").Value
arrMatrix(8, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("K10").Value
arrMatrix(9, 1, 1) = mainWorkBook.Sheets("Sheet1").Range("K11").Value
arrMatrix(9, 2, 1) = mainWorkBook.Sheets("Sheet1").Range("K12").Value
arrMatrix(9, 3, 1) = mainWorkBook.Sheets("Sheet1").Range("K13").Value

arrMatrix(7, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("L5").Value
arrMatrix(7, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("L6").Value
arrMatrix(7, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("L7").Value
arrMatrix(8, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("L8").Value
arrMatrix(8, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("L9").Value
arrMatrix(8, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("L10").Value
arrMatrix(9, 1, 2) = mainWorkBook.Sheets("Sheet1").Range("L11").Value
arrMatrix(9, 2, 2) = mainWorkBook.Sheets("Sheet1").Range("L12").Value
arrMatrix(9, 3, 2) = mainWorkBook.Sheets("Sheet1").Range("L13").Value

arrMatrix(7, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("M5").Value
arrMatrix(7, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("M6").Value
arrMatrix(7, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("M7").Value
arrMatrix(8, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("M8").Value
arrMatrix(8, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("M9").Value
arrMatrix(8, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("M10").Value
arrMatrix(9, 1, 3) = mainWorkBook.Sheets("Sheet1").Range("M11").Value
arrMatrix(9, 2, 3) = mainWorkBook.Sheets("Sheet1").Range("M12").Value
arrMatrix(9, 3, 3) = mainWorkBook.Sheets("Sheet1").Range("M13").Value

End Function

Function FnFillValues()
'intChar = 69
'j = 1
'Set mainWorkBook = ActiveWorkbook
'For k = 1 To 9
'   For m = 69 To 77
'      For k = 1 To 3
'          For i = 1 To 3
'             arrMatrix(k, i, j) = mainWorkBook.Sheets("Sheet1").Range(Chr(m) & i + 4).Value
'        Next
'       j = j + 1
'  Next
'Next
'Next

mainWorkBook.Sheets("Sheet1").Range("E5").Value = arrMatrix(1, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("E6").Value = arrMatrix(1, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("E7").Value = arrMatrix(1, 3, 1)
mainWorkBook.Sheets("Sheet1").Range("E8").Value = arrMatrix(2, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("E9").Value = arrMatrix(2, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("E10").Value = arrMatrix(2, 3, 1)
mainWorkBook.Sheets("Sheet1").Range("E11").Value = arrMatrix(3, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("E12").Value = arrMatrix(3, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("E13").Value = arrMatrix(3, 3, 1)

mainWorkBook.Sheets("Sheet1").Range("F5").Value = arrMatrix(1, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("F6").Value = arrMatrix(1, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("F7").Value = arrMatrix(1, 3, 2)
mainWorkBook.Sheets("Sheet1").Range("F8").Value = arrMatrix(2, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("F9").Value = arrMatrix(2, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("F10").Value = arrMatrix(2, 3, 2)
mainWorkBook.Sheets("Sheet1").Range("F11").Value = arrMatrix(3, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("F12").Value = arrMatrix(3, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("F13").Value = arrMatrix(3, 3, 2)

mainWorkBook.Sheets("Sheet1").Range("G5").Value = arrMatrix(1, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("G6").Value = arrMatrix(1, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("G7").Value = arrMatrix(1, 3, 3)
mainWorkBook.Sheets("Sheet1").Range("G8").Value = arrMatrix(2, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("G9").Value = arrMatrix(2, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("G10").Value = arrMatrix(2, 3, 3)
mainWorkBook.Sheets("Sheet1").Range("G11").Value = arrMatrix(3, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("G12").Value = arrMatrix(3, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("G13").Value = arrMatrix(3, 3, 3)

mainWorkBook.Sheets("Sheet1").Range("H5").Value = arrMatrix(4, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("H6").Value = arrMatrix(4, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("H7").Value = arrMatrix(4, 3, 1)
mainWorkBook.Sheets("Sheet1").Range("H8").Value = arrMatrix(5, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("H9").Value = arrMatrix(5, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("H10").Value = arrMatrix(5, 3, 1)
mainWorkBook.Sheets("Sheet1").Range("H11").Value = arrMatrix(6, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("H12").Value = arrMatrix(6, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("H13").Value = arrMatrix(6, 3, 1)

mainWorkBook.Sheets("Sheet1").Range("I5").Value = arrMatrix(4, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("I6").Value = arrMatrix(4, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("I7").Value = arrMatrix(4, 3, 2)
mainWorkBook.Sheets("Sheet1").Range("I8").Value = arrMatrix(5, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("I9").Value = arrMatrix(5, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("I10").Value = arrMatrix(5, 3, 2)
mainWorkBook.Sheets("Sheet1").Range("I11").Value = arrMatrix(6, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("I12").Value = arrMatrix(6, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("I13").Value = arrMatrix(6, 3, 2)

mainWorkBook.Sheets("Sheet1").Range("J5").Value = arrMatrix(4, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("J6").Value = arrMatrix(4, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("J7").Value = arrMatrix(4, 3, 3)
mainWorkBook.Sheets("Sheet1").Range("J8").Value = arrMatrix(5, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("J9").Value = arrMatrix(5, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("J10").Value = arrMatrix(5, 3, 3)
mainWorkBook.Sheets("Sheet1").Range("J11").Value = arrMatrix(6, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("J12").Value = arrMatrix(6, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("J13").Value = arrMatrix(6, 3, 3)

mainWorkBook.Sheets("Sheet1").Range("K5").Value = arrMatrix(7, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("K6").Value = arrMatrix(7, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("K7").Value = arrMatrix(7, 3, 1)
mainWorkBook.Sheets("Sheet1").Range("K8").Value = arrMatrix(8, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("K9").Value = arrMatrix(8, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("K10").Value = arrMatrix(8, 3, 1)
mainWorkBook.Sheets("Sheet1").Range("K11").Value = arrMatrix(9, 1, 1)
mainWorkBook.Sheets("Sheet1").Range("K12").Value = arrMatrix(9, 2, 1)
mainWorkBook.Sheets("Sheet1").Range("K13").Value = arrMatrix(9, 3, 1)

mainWorkBook.Sheets("Sheet1").Range("L5").Value = arrMatrix(7, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("L6").Value = arrMatrix(7, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("L7").Value = arrMatrix(7, 3, 2)
mainWorkBook.Sheets("Sheet1").Range("L8").Value = arrMatrix(8, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("L9").Value = arrMatrix(8, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("L10").Value = arrMatrix(8, 3, 2)
mainWorkBook.Sheets("Sheet1").Range("L11").Value = arrMatrix(9, 1, 2)
mainWorkBook.Sheets("Sheet1").Range("L12").Value = arrMatrix(9, 2, 2)
mainWorkBook.Sheets("Sheet1").Range("L13").Value = arrMatrix(9, 3, 2)

mainWorkBook.Sheets("Sheet1").Range("M5").Value = arrMatrix(7, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("M6").Value = arrMatrix(7, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("M7").Value = arrMatrix(7, 3, 3)
mainWorkBook.Sheets("Sheet1").Range("M8").Value = arrMatrix(8, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("M9").Value = arrMatrix(8, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("M10").Value = arrMatrix(8, 3, 3)
mainWorkBook.Sheets("Sheet1").Range("M11").Value = arrMatrix(9, 1, 3)
mainWorkBook.Sheets("Sheet1").Range("M12").Value = arrMatrix(9, 2, 3)
mainWorkBook.Sheets("Sheet1").Range("M13").Value = arrMatrix(9, 3, 3)

End Function

Press the button till the SUDOKU is solved.

SUDOKU SOLVER-2
SUDOKU SOLVER-2
SUDOKU SOLVER-3
SUDOKU SOLVER-3

Download Link : SUDOKU Solver



Also Read:

  1. VBA Excel – Looping Through a Range of Cells
  2. Excel-VBA : Prevent Changing the WorkSheet Name
  3. VBA-Excel: Convert Numbers (Dollars, Euros) into Words or Text - Till Trillions
  4. VBA-Excel: Copy/Paste data - Copy the Entire data from one sheet to another