用excel和vba解數(shù)獨(dú)

好的,下面是解答數(shù)獨(dú)過程的VBA代碼。它會(huì)依次對A區(qū)域和B區(qū)域中的所有數(shù)獨(dú)游戲進(jìn)行求解,并將解答填充回對應(yīng)的區(qū)域中。
```
Sub SolveSudokus()
??'解答A區(qū)域中的所有數(shù)獨(dú)游戲
??Dim i As Integer
??For i = 1 To 4
????'獲取數(shù)獨(dú)游戲所在的位置和大小
????Dim topLeft As Range
????Set topLeft = Range("A" & (3 * i - 2) & ":I" & (3 * i))
????'讀取數(shù)獨(dú)游戲的數(shù)據(jù)
????Dim data(1 To 81) As Integer
????For j = 1 To 9
??????For k = 1 To 9
????????If IsNumeric(topLeft.Cells(j, k).Value) Then
??????????data((j - 1) * 9 + k) = topLeft.Cells(j, k).Value
????????Else
??????????data((j - 1) * 9 + k) = 0
????????End If
??????Next k
????Next j
????'解答數(shù)獨(dú)游戲
????Dim solver As New SudokuSolver
????solver.Solve data
????'將解答填充回對應(yīng)的區(qū)域中
????For j = 1 To 9
??????For k = 1 To 9
????????If data((j - 1) * 9 + k) > 0 Then
??????????topLeft.Cells(j, k).Value = data((j - 1) * 9 + k)
????????End If
??????Next k
????Next j
??Next i
??'解答B(yǎng)區(qū)域中的所有數(shù)獨(dú)游戲
??For i = 1 To 9
????'獲取數(shù)獨(dú)游戲所在的位置和大小
????Dim topLeft As Range
????Set topLeft = Range("H" & (i + 1) & ":P" & (i + 9))
????'讀取數(shù)獨(dú)游戲的數(shù)據(jù)
????Dim data(1 To 81) As Integer
????For j = 1 To 9
??????For k = 1 To 9
????????If IsNumeric(topLeft.Cells(j, k).Value) Then
??????????data((j - 1) * 9 + k) = topLeft.Cells(j, k).Value
????????Else
??????????data((j - 1) * 9 + k) = 0
????????End If
??????Next k
????Next j
????'解答數(shù)獨(dú)游戲
????Dim solver As New SudokuSolver
????solver.Solve data
????'將解答填充回對應(yīng)的區(qū)域中
????For j = 1 To 9
??????For k = 1 To 9
????????If data((j - 1) * 9 + k) > 0 Then
??????????topLeft.Cells(j, k).Value = data((j - 1) * 9 + k)
????????End If
??????Next k
????Next j
??Next i
End Sub
```
這個(gè)VBA過程主要是依次對A區(qū)域和B區(qū)域中的所有數(shù)獨(dú)游戲進(jìn)行求解,首先讀取數(shù)獨(dú)游戲的數(shù)據(jù),然后調(diào)用`solver.Solve`方法進(jìn)行求解,最后將解答填充回對應(yīng)的區(qū)域中。