两个按钮的VBA代码如下: Private Sub CommandButton1_Click() Dim a(1 To 9) As Byte '9*9依次轮询 For i = 11 To 19 For j = 1 To 9 '先放入1-9,准备逐个排除 For k = 1 To 9 a(k) = k Next '排除列 For m = 1 To 9 If (Cells(j, m) <> "") Then a(Cells(j, m)) = 0 End If Next '排除行 For m = 1 To 9 If (Cells(m, i - 10) <> "") Then a(Cells(m, i - 10)) = 0 End If Next '排除块 For m = 1 To 3 For n = 1 To 3 If (Cells(m + Int((j - 1) / 3) * 3, n + Int((i - 11) / 3) * 3) <> "") Then a(Cells(m + Int((j - 1) / 3) * 3, n + Int((i - 11) / 3) * 3)) = 0 End If Next Next '清空右边9*9 Cells(j, i) = "" '前面排除时,将排除的数据记录为0,这里剔除掉,只保留剩余数据 For m = 1 To 9 If (Cells(j, i - 10) = "" And a(m) <> 0) Then Cells(j, i) = Cells(j, i) & m End If Next Next Next End Sub Private Sub CommandButton2_Click() '将右边9*9的确认数据,填入左边单元格 For i = 1 To 9 For j = 1 To 9 If (Len(Cells(j, i + 10)) = 1) Then Cells(j, i) = Cells(j, i + 10) End If Next Next End Sub