Sub z()
Range(Cells(1, 1), Cells(100, 100)).Clear
n1=5
n2=3
n3=4
k = 1
A = InitMatrix(n1, k, 1)
k = k + n1 + 2
B = InitMatrix(n2, k, 1)
k = k + n2 + 2
C = InitMatrix(n3, k, 1)
End Sub
Function InitMatrix(n, cx, cy)
ReDim A(n, n)
For i = LBound(A, 1) To UBound(A, 1)
For j = LBound(A, 2) To UBound(A, 2)
A(i, j) = Rnd * 200 - 100
Cells(cx + i, cy + j) = A(i, j)
Next
Next
Cells(cx, cy + n + 1) = "PositiveAverage ="
Cells(cx, cy + n + 2) = PositiveAverage(A)
InitMatrix = A
End Function
Function PositiveAverage(A)
For i = LBound(A, 1) To UBound(A, 1)
For j = LBound(A, 2) To UBound(A, 2)
If A(i, j) > 0 Then
s = s + A(i, j)
k = k + 1
End If
Next
Next
PositiveAverage = s / k
End Function