Create a diagonal matrix in Excel?

Solved
lola8 Posted messages 2 Status Member -  
 Nadia -
Hello,

I have a 37x1 vector, which is a column of 37 rows in Excel, and I would like each element of this vector to be on the diagonal of a 37x37 square matrix with zeros around it. I think I need to use a macro, but how?
thanks in advance

3 answers

random Posted messages 1612 Status Member 155
 
no one needs a macro

I name my vector vector

I start my matrix at c1

the formula is IF(ROW()=COLUMN()-2,INDEX(vector,ROW(),1),0)
4
Anonymous user
 
Hello,

Suggestion:

Sub Matrice() Dim Boucle, Position As Integer Dim ValeurTMP As Variant For Boucle = 0 To 36 Range("A" & (Boucle + 1)).Select ValeurTMP = ActiveCell.Offset(0, 0).Value For Position = 0 To 36 If (Boucle = Position) Then ActiveCell.Offset(0, Position).Value = ValeurTMP Else ActiveCell.Offset(0, Position).Value = 0 End If Next Position Next Boucle End Sub


Lupin

--
~The essential is invisible to the eye~
~One sees clearly only with the heart~
0
lola8 Posted messages 2 Status Member
 
thank you for everything lupin, it's spot on...
with pleasure.
0
Doc
 
Hello,

I have an Excel 2007 list with two columns (A, B) and 635 rows. I need to create a square matrix in order to study a network.
I have read all of the EXCEL help for more than 50 hours of work, nothing. I don’t know how to program.

Thanks in advance,

Best regards
-1
Nadia
 
Hi,
I have exactly the same problem as you... Did you manage to solve it? If so, could you give me some tips!!!

Thank you
Nadia

You can contact me at moi-nadia@hotmail.fr
0