Friday, August 19, 2016

xlMatrix series: xlMADD - summing 2 matrixes

Report any errors to afstblogs@gmail.com







Function xlMADD(M1, M2)

    Dim rslt()
    Dim i, j
    Dim rws1, rws2, cls1, cls2
   
    rws1 = M1.Rows.Count
    cls1 = M1.Columns.Count
    rws2 = M2.Rows.Count
    cls2 = M2.Columns.Count
    ReDim rslt(1 To rws1, 1 To cls1)
   
    If (rws1 <> rws2) Or (cls1 <> cls2) Then
        xlMADD = "xlERR"
    Else
        For i = 1 To rws1
            For j = 1 To cls1
                rslt(i, j) = M1(i, j) + M2(i, j)
            Next j
        Next i
        xlMADD = rslt
    End If
        
End Function

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.