VBA to generating a correlation 
/////////////////////////////////////
Source:http://www.ozgrid.com/forum/showthread.php?t=45045

Function corrMatrix(dataRange As Object) As Variant 
    On Error Goto 20 
    Dim r As Integer, n As Integer, rr As Integer, i As Integer, j As Integer, k As Integer, doit As Integer 
    Dim x() As Variant, mc() As Double, ss() As Double, m() As Double, ob As Object 
    r = dataRange.Rows.Count 
    n = dataRange.Columns.Count 
    Redim ss(1 To n, 1 To n), m(1 To n), x(1 To n), mc(1 To n, 1 To n) 
    rr = r 
    For i = 1 To r 
        doit = 0 
        For j = 1 To n 
            Set ob = dataRange.Cells(i, j) 
            doit = doit + Application.Count(ob) 
            x(j) = ob.Value 
        Next j 
        If doit = n Then 
            For j = 1 To n 
                m(j) = m(j) + x(j) 
                For k = 1 To j 
                    ss(j, k) = ss(j, k) + x(j) * x(k) 
                Next k 
            Next j 
        Else 
            rr = rr - 1 
        End If 
    Next i 
    For j = 1 To n 
        ss(j, j) = (ss(j, j) - m(j) * m(j) / rr) ^ 0.5 
        mc(j, j) = 1 
        For k = 1 To j - 1 
            ss(j, k) = ss(j, k) - m(j) * m(k) / rr 
            mc(j, k) = ss(j, k) / (ss(j, j) * ss(k, k)) 
            mc(k, j) = mc(j, k) 
        Next k 
    Next j 
    corrMatrix = mc 
    Exit Function 
    20 corrMatrix = CVErr(xlErrValue) 
End Function

/////////////////////////////////////

Links 
/////////////////////////////////////
Using Excel for matrix
    https://web.stanford.edu/~wfsharpe/mia/mat/mia_mat4.htm
    http://facweb.cs.depaul.edu/mobasher/classes/csc575/assignments/MatrixOperations-Excel2007.pdf

    https://support.office.com/en-us/article/Guidelines-and-examples-of-array-formulas-7d94a64e-3ff3-4686-9372-ecfd5caa57c7

YouTube
   Matrix Multiplication and Inverse in Exce           (5m22s)
       https://www.youtube.com/watch?v=G8w-d9U3PJM
   Matrix transpose and matrix multiplication by Excel (7m29s) 
      https://www.youtube.com/watch?v=6UWG_L8TceU
   Matrix Math/Excel-1                                 (5m35s)
      https://www.youtube.com/watch?v=Kp3F-cJwIJ8
  
VBA for covariance
    http://canisius.edu/~yany/excel/varCov.txt

VBA for correlation
    http://www.ozgrid.com/forum/showthread.php?t=45045
    http://canisius.edu/~yany/excel/VBAcorreMatrix.txt

/////////////////////////////////////