PC Review


Reply
Thread Tools Rate Thread

Adding matrices

 
 
New Member
Join Date: Jun 2010
Posts: 1
 
      7th Jun 2010
Hi everybody,

function (MSUM(Array1, Array2) ) adds two matrices. Everything works well when inputs are ranges from the sheet. (e.g. MSUM(A1:B2,A1:B2))

But when I input functions inside, it returns #Value. (e.g. MSUM(Transpose(A1:B2),Transpose(A1:B2)) )

Please help people!

Here is the code:

Function MSUM(Array1 As Variant, Array2 As Variant)

Dim n As Integer, m As Integer, u As Integer, v As Integer
Dim i As Integer, j As Integer
Dim Ans() As Variant

'Figuring out dimensions of the Array1 and Array2. UBound, LBound for some reason do not work for me properly

For i = 1 To 30
For j = 1 To 30
If Array1(1, j) = 0 And Array2(1, j) = 0 Then
m = j - 1 ' # of columns
v = j - 1
Exit For
End If
Next j
If Array1(i, 1) = 0 And Array2(i, 1) = 0 Then
n = i - 1 ' # of rows
u = i - 1
Exit For
End If
Next i

ReDim Ans(1 To n, 1 To m)

'Getting result
For i = 1 To n
For j = 1 To m
Ans(i, j) = Array1(i, j) + Array2(i, j)
Next j
Next i

MSUM = Ans
End Function

Regards,
Marik
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing two matrices mahadevan.swamy@gmail.com Microsoft Excel Misc 1 1st May 2007 02:20 PM
inverse matrices =?Utf-8?B?Q2hleQ==?= Microsoft Excel Misc 6 31st Jan 2007 12:14 AM
How to solve y =f(x,y) using matrices? =?Utf-8?B?QW5l?= Microsoft Excel Worksheet Functions 1 27th Jul 2005 02:37 AM
Re: transpose matrices Sander Lablans Microsoft Excel Programming 4 4th Aug 2003 04:20 PM
Re: transpose matrices Alan Beban Microsoft Excel Programming 1 1st Aug 2003 06:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:45 AM.