Option Explicit
Sub aaa()
Const n = 5
Dim A(1 To n, 1 To n) As Long, E(1 To n, 1 To n) As Long
Dim i As Integer, j As Integer, k As Integer
' инициализация матриц
For i = 1 To n
For j = 1 To n
If i = j Then
A(i, j) = 0 ' глупо тут вычислять i-j
E(i, j) = 1
Else
A(i, j) = i - 2 * j
E(i, j) = 0
End If
Next j
Next i
' A^2 - просто умножение матрицы самой на себя
Dim B(1 To n, 1 To n) As Long
For i = 1 To n
For j = 1 To n
B(i, j) = 0
For k = 1 To n
B(i, j) = B(i, j) + A(i, k) * A(k, j)
Next k
Next j
Next i
' 3A^2 - A + 7E
For i = 1 To n
For j = 1 To n
B(i, j) = 3 * B(i, j) - A(i, j) + 7 * E(i, j)
Next j
Next i
' Поиск столбца B с максимальной суммой модулей элементов
Dim S As Long, Max As Long, jj As Long
Max = -1000000
For j = 1 To n
S = 0
For i = 1 To n
S = S + Abs(B(i, j))
Next i
If S > Max Then
Max = S
jj = j
End If
Next j
' Вывод на лист Excel
Range(Cells(1, 1), Cells(n + 1, 2)).Clear
Cells(1, 1) = "Столбец " + CStr(jj)
For i = 1 To n
Cells(i + 1, 1) = B(i, jj)
Next i
End Sub