' Generates (Pan) Magic Squares of order 7 based on Sudoku Comparable Squares
' Tested with Office 2007 under Windows 7
Sub CnstrSqrs7a()
Dim a(49), b(2, 49)
n2 = 0: n9 = 0: k1 = 1: k2 = 1
s1 = 175
' Options
' 1. A1: shift 2 columns to the left / A3: shift 2 columns to the right
' 2. A1: shift 2 columns to the left / A4: shift 3 columns to the right
' 3. A1: shift 2 columns to the left / A2: shift 3 columns to the left
' 4. A2: shift 3 columns to the left / A3: shift 2 columns to the right
' 5. A2: shift 3 columns to the left / A4: shift 3 columns to the right
' 6. A2: shift 3 columns to the left / A1: shift 2 columns to the left
' Select Option
Sht1 = "Sudoku71" : Sht2 = "Sudoku73"
' Sht1 = "Sudoku71" : Sht2 = "Sudoku74"
' Sht1 = "Sudoku71" : Sht2 = "Sudoku72"
' Sht1 = "Sudoku72" : Sht2 = "Sudoku73"
' Sht1 = "Sudoku72" : Sht2 = "Sudoku74"
' Sht1 = "Sudoku72" : Sht2 = "Sudoku71"
Sheets("Klad1").Select
y = MsgBox("Locked", vbCritical, "Routine CnstrCbs7a")
End
n4 = 720
For j1 = 1 To n4
For j2 = 1 To n4
j10 = j1: j20 = 1: Sht = Sht1: GoSub 100 'Read Sudoku Comparable Square 1
j10 = j2: j20 = 2: Sht = Sht2: GoSub 100 'Read Sudoku Comparable Square 2
For j4 = 1 To 49
a(j4) = b(1, j4) + 7 * b(2, j4) + 1
Next j4
' GoSub 200: If fl1 = 0 Then GoTo 20 'Check Additional Properties (Optional)
GoSub 300: If fl1 = 0 Then GoTo 20 'Check identical numbers
'********************** Only Counting **************************
' Cells(2, 1).Value = j1
' Cells(2, 2).Value = j2
' Cells(2, 4).Select: Cells(2, 4).Value = Cells(2, 4).Value + 1
'***************************************************************
n9 = n9 + 1: GoSub 600 'Print results (squares)
20 Next j2
Next j1
t2 = Timer
t10 = Str(t2 - t1) + " sec., " + Str(n9) + " Solutions for sum" + Str(s1)
y = MsgBox(t10, 0, "Routine CnstrSqrs7a")
End
' Read Sudoku Comparable Cubes (line format)
100
For i1 = 1 To 49
b(j20, i1) = Sheets(Sht).Cells(j10, i1).Value
Next i1
Return
' Check identical numbers
300 fl1 = 1
For i1 = 1 To 49
a2 = a(i1)
For i2 = (1 + i1) To 49
If a2 = a(i2) Then fl1 = 0: Return
Next i2
Next i1
Return
' Print results (selected numbers)
500 For i1 = 1 To 49
Cells(n9, i1).Value = a(i1)
Next i1
Return
' Print results (squares)
600 n2 = n2 + 1
If n2 = 5 Then
n2 = 1: k1 = k1 + 8: k2 = 1
Else
If n9 > 1 Then k2 = k2 + 8
End If
Cells(k1, k2 + 1).Select
Cells(k1, k2 + 1).Font.Color = -4165632
Cells(k1, k2 + 1).Value = n9
i3 = 0
For i1 = 1 To 7
For i2 = 1 To 7
i3 = i3 + 1
Cells(k1 + i1, k2 + i2).Value = a(i3)
Next i2
Next i1
Return
End Sub