Alex has attended:
Excel VBA Introduction course
Multiplying matrices
Hi i am trying to transpose a matrix then multiply the original matrix by the transposed one. I am not sure if you can do this without creating separate matrices but so far i have this and it does not seem to be working, i was wondering if you could point me in the right direction.
I wish to transpose "myarray" then with this transposed matrix("myarray2") multiply it by "myarray"
Thanks
Sub transpose()
Dim myarray As Variant
Application.Worksheets("Overlap").Activate
myarray = Range("x3:ak16")
Sheets("Transpose").Range("b3:o16").Value = Application.transpose(myarray)
Dim myarray2 As Variant
Application.Worksheets("Transpose").Activate
myarray2 = Range("b3:o16")
Range("x3:ak16").Value = myarray.Value * myarray2.Value
end sub()
RE: Multiplying matrices
Hello Alex,
Thank you for your post. Our trainers who are able to answer your question are all in training today. One of them will get back to you tomorrow. I hope this is in order.
Kind regards
Marius Barnard
Best STL
RE: Multiplying matrices
great thanks
RE: Multiplying matrices
Hi Alex,
Please have a look at the code below.
You need to multiply each stored cell in the first array with each cell in the second array.
I have used two for next loops to run through the 2 arrays.
I hope this is what you are looking for.
Sub transpose()
Dim myarray As Variant
Dim myarray2 As Variant
Dim iRow As Integer
Dim iCol As Integer
Worksheets(1).Activate
myarray = Range("a1:b2")
Sheets(2).Range("a1:b2").Value = Application.transpose(myarray)
Worksheets(2).Activate
myarray2 = Range("a1:d2")
Sheets(1).Activate
For iRow = LBound(myarray, 1) To UBound(myarray, 1)
For iCol = LBound(myarray, 2) To UBound(myarray, 2)
Cells(iRow, iCol) = myarray(iRow, iCol) * myarray2(iRow, iCol)
Next
Next
End Sub
Kind regards
Jens Bonde
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector