Sub MaPhuong(N As Integer)
Const PntMir = "P"
Const VerMir = "V"
Const HorMir = "H"
Const IgnMir = "I"
Dim iRow As Integer
Dim iCol As Integer
Dim arr() As Integer
ReDim arr(1 To N, 1 To N)
For iRow = 1 To N
For iCol = 1 To N
arr(iRow, iCol) = (iRow - 1) * N + iCol
Next
Next
Dim iRowProc As Integer
iRowProc = N \ 2
Dim sKey As String
sKey = String(iRowProc \ 2, PntMir) & IIf(iRowProc Mod 2 = 1, VerMir & HorMir, "")
sKey = sKey & String(iRowProc - Len(sKey), IgnMir)
For iRow = 1 To iRowProc
For iCol = 1 To iRowProc
Select Case Mid(sKey, iCol, 1)
Case PntMir:
Swap arr(iRow, iCol), arr(N - iRow + 1, N - iCol + 1)
Swap arr(iRow, N - iCol + 1), arr(N - iRow + 1, iCol)
Case VerMir:
Swap arr(iRow, iCol), arr(N - iRow + 1, iCol)
Case HorMir:
Swap arr(iRow, iCol), arr(iRow, N - iCol + 1)
End Select
Next
sKey = Right(sKey, 1) & Left(sKey, Len(sKey) - 1)
Next
Range("A1").Resize(N, N) = arr
End Sub
Sub Swap(ByRef iNum1 As Integer, ByRef iNum2 As Integer)
Dim iTemp As Integer
iTemp = iNum1
iNum1 = iNum2
iNum2 = iTemp
End Sub