Public Sub glav_diag() Dim i As Integer Dim j As Integer Dim q As Double Dim cond As Integer n = InputBox("n=") ReDim arr(n, n) q = 1 cond = 0 ' Generation of array For i = 1 To n For j = 1 To n arr(i, j) = Int((-20 - 30 + 1) * Rnd + 30) Cells(i, j).Value = arr(i, j) Cells(i, j).Interior.ColorIndex = xlNone Next j Next i For j = 1 To n For i = 1 To n If ((arr(i, j) > 0) And (arr(i, j) Mod 2 = 0)) Then q = q * arr(i, j) cond = cond + 1 Cells(i, j).Interior.Color = vbCyan End If Next i If (cond > 0) Then Cells(n + 1, j).Value = q Cells(n + 1, j).Interior.Color = vbGreen Else Cells(n + 1, j).Value = 0 Cells(n + 1, j).Interior.Color = vbGreen End If cond = 0 q = 1 Next j End Sub