multiplying matrices

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Multiplying matrices

Multiplying matrices

resolvedResolved · Medium Priority · Version 2013

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

RE: Multiplying matrices

Thats brilliant

Thanks very much!!!

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Importing Numbers in Excel 2010

Occasionally, when importing data into Excel you find that the some of the imported values are treated as text.

To convert these numbers to actual values, click on an empty cell and press Ctrl+C.

Next, select the range that contains the values you need to change and in the Clipboard Group on the Home tab, click the Paste drop-down arrow and choose Paste Special. In the Paste Special dialog box, select Add and then click OK.

View all Excel hints and tips


Server loaded in 0.09 secs.