Anthony's VBA Forum Index Anthony's VBA Forum
Where the knowledge is shared
Menu
 Anthony's VBA Forum IndexHome Page
 Anthony's VBA Forum IndexForum Index
FAQFAQ
MemberlistMemberlist
UsergroupsUsergroups
RegisterRegister
ProfileProfile
Log in to check your private messagesMessages
Log inLogin/Out

Quick Search

Advanced Search

Links
Consulting
Products

Who's Online
[ Administrator ]
[ Moderator ]


VBA to find matrix trace

 
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA
View previous topic :: View next topic  
Author Message
latitude



Joined: 06 Apr 2006
Posts: 1

PostPosted: Thu Apr 06, 2006 6:35 pm    Post subject: VBA to find matrix trace Reply with quote

I have been assigned a problem for class the problem is:

Create a user defined function for the trace of a square matrix. The trace is the sum of the diagonal elements. The input is a range. The output is a double. This function should also test if the number of rows = the number of columns. If not, return the string #ERROR. Because the function can return either a number or a string, the function type should be a variant. The trace is the main diagonal sum.

ex.
4 3 1
5 4 2
6 7 9

The trace is 4 + 4 + 9 = 17

I know how to do everything except get the trace to work in excel.

here is my code so far

Public Function trace(x As Range) As Variant

If x.Rows.Count > x.Columns.Count Or x.Rows.Count < x.Columns.Count Then

trace = "Error"

If x.Rows.Count = x.Columns.Count Then
trace = ????????- here is the part i need help with
End If
End If
End Function
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group