Help with a VBA Formula

jsowa

New Member
Joined
Dec 10, 2019
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
Hello,

I have a problem with excel. I've been trying to put a matrix multiplication formula into an excel macro, and cant help to think there's an easier way, but just starting to learn VBA, its a bit rough... Can someone help me with this?

Im trying to have the MMULT return the amount of cells in the Std. Deviation tab, and came up with a very long excel formula, but putting it into a macro said it was too long to run.

Can someone help with putting this to a VBA code?

Heres the formula
=IFERROR(MMULT(B4:B18,TRANSPOSE(B4:B18)),IFERROR(MMULT(B4:B17,TRANSPOSE(B4:B17)),IFERROR(MMULT(B4:B16,TRANSPOSE(B4:B16)),IFERROR(MMULT(B4:B15,TRANSPOSE(B4:B15)),IFERROR(MMULT(B4:B14,TRANSPOSE(B4:B14)),IFERROR(MMULT(B4:B13,TRANSPOSE(B4:B13)),IFERROR(MMULT(B4:B12,TRANSPOSE(B4:B12)),IFERROR(MMULT(B4:B11,TRANSPOSE(B4:B11)),IFERROR(MMULT(B4:B10,TRANSPOSE(B4:B10)),IFERROR(MMULT(B4:B9,TRANSPOSE(B4:B9)),IFERROR(MMULT(B4:B8,TRANSPOSE(B4:B8)),IFERROR(MMULT(B4:B7,TRANSPOSE(B4:B7)),IFERROR(MMULT(B4:B6,TRANSPOSE(B4:B6)),(MMULT(B4:B5,TRANSPOSE(B4:B5))))))))))))))))

1576005859221.png
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Welcome to the MrExcel forum.

Instead of that long formula, why not just:

=B4:B18*TRANSPOSE(B4:B18)

In my limited testing, I got the same results as your formula, except that instead of the #N/A's I got zeros. Then entering it via VBA is:

Range("E4:S18").FormulaArray = "=B4:B18*TRANSPOSE(B4:B18)"

You can preserve your original formula with something like:

=MMULT(OFFSET(B4,0,0,COUNT(B4:B18)),TRANSPOSE(OFFSET(B4,0,0,COUNT(B4:B18))))
 
Upvote 0
Welcome to the MrExcel forum.

Instead of that long formula, why not just:

=B4:B18*TRANSPOSE(B4:B18)

In my limited testing, I got the same results as your formula, except that instead of the #N/A's I got zeros. Then entering it via VBA is:

Range("E4:S18").FormulaArray = "=B4:B18*TRANSPOSE(B4:B18)"

You can preserve your original formula with something like:

=MMULT(OFFSET(B4,0,0,COUNT(B4:B18)),TRANSPOSE(OFFSET(B4,0,0,COUNT(B4:B18))))


Wow, thank you so much! It worked perfectly!
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top