Sub correlationz()
Dim t As Single
t = Timer
Dim n As Long, m As Integer, u As Integer
Dim z() As Single, y() As Single
Dim v, k As Single, q As Single, s As Integer
Dim stp As Integer, i As Long, j As Integer
Sheets("base").Activate
n = [a3].End(xlDown).Row - 2
m = [a3].End(xlToRight).Column
If m > 300 Then stp = 200 Else stp = Int(m / 2) + 1
If m > 10000 Then stp = 100
ReDim z(1 To n, 1 To m), y(1 To stp, 1 To n)
q = (n - 1) ^ 0.5
With Application
For j = 1 To m
v = Cells(3, j).Resize(n)
If .StDev(v) > 0 Then k = .StDev(v) * q Else k = 1
v = .Standardize(v, .Average(v), k)
For i = 1 To n
z(i, j) = v(i, 1)
If j Mod stp = 0 Or j = m Then
u = j
For s = 1 To stp
y(s, i) = z(i, u - stp + s)
Next s
End If
Next i
If j = u Then
Sheets("correlmatrix").Cells(u - stp + 2, 2). _
Resize(stp, u) = .MMult(y, z)
For s = 1 To stp
Sheets("correlmatrix").Cells(2, u - stp + s + 2). _
Resize(u - stp + s).ClearContents
Next s
End If
Next j
End With
MsgBox "Code took " & Format(Timer - t, "0.000") & " secs"
End Sub