MMULT in VBA - 1004 error

James_Latimer

Active Member
Joined
Jan 20, 2009
Messages
415
Excel 2016

I was hoping someone could give me some pointers please, i'm having some issues with the following and can't quite understand why.

I have the following code

Code:
Dim var1 as Variant, var2 as Variant

var1 = Sheets("Sheet1").Range("R16:AC16")
var2 = Sheets("Sheet2").Range("P4:P15")

MsgBox (Application.WorksheetFunction.MMult(var1, var2))

I then get the following error 'Run-time error 1004: Unable to get the MMult property of the WorksheetFunction Class'

If i do the same thing on the front end of Excel (using the same ranges) then it works fine. Can someone throw me a fricking bone here please?

Thank you kind Excelers.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Works fine for me (up until the type mismatch when you try and Msgbox an array). I assume you meant to use two different sheets in the code?
 
Last edited:
Upvote 0
Returning the 2D array via msgbox may be tricky, but notice that:


Excel 2010
PQRSTUVWXYZAAABAC
495497263634599090185490
54244322828204404082440
62122161414102202041220
73183242121153303061830
84244322828204404082440
974275649493577070144270
1084886456564088080164880
113183242121153303061830
122122161414102202041220
133183242121153303061830
144244322828204404082440
1510601080707050101001002060100
16618775110102610
Sheet1
Cell Formulas
RangeFormula
R4:AC15{=MMULT(P4:P15,R16:AC16)}
Press CTRL+SHIFT+ENTER to enter array formulas.


while:
Rich (BB code):
Sub mtxmlt()
Dim var1 As Variant, var2 As Variant
var1 = Range("R16:AC16")
var2 = Range("P4:P15")
Range("r4:ac15") = Application.MMult(var2, var1)
End Sub

gives you:


Excel 2010
PQRSTUVWXYZAAABAC
495497263634599090185490
54244322828204404082440
62122161414102202041220
73183242121153303061830
84244322828204404082440
974275649493577070144270
1084886456564088080164880
113183242121153303061830
122122161414102202041220
133183242121153303061830
144244322828204404082440
1510601080707050101001002060100
16618775110102610
Sheet1
 
Last edited:
Upvote 0
MsgBox isn't happy with an array, even a single-element array like yours.

Code:
MsgBox (Application.WorksheetFunction.MMult(var1, var2)[COLOR="#FF0000"](1)[/COLOR])
 
Upvote 0
Thanks for the quick replies peeps. Genuinely appreciated.... clearly i dont know what i am doing!
Out of curiosity, I have the following formula within a table which returns the value 0.5166
Code:
=((EXP(MMULT($R$16:$AC$16,'Poutput'!$P$4:$P$15))^R15)*EXP(-(EXP(MMULT($R$16:$AC$16,'Poutput'!$P$4:$P$15))))/FACT(R15))

I was wanting to create some code that would generate this table via VBA and just put the values in rather than having all the formulae. I was wanting to create an array to save the results to and then dump the values into a table on a worksheet right at the end...

Code:
outputFlows(countCycle, countAttacks) = ((Exp(Application.MMult(fixedP, baselineP) ^ countAttacks) * Exp(-(Exp(Application.MMult(fixedP, baselineP)))) / Application.Fact(countAttacks)))

Where fixedP is a fixed range (row), baselineP is a fixed range (column), countAttacks is an integer between 0 and 11. The idea being that i loop through what would be the columns and rows of the table and generate it in VBA using the above.

Is it even possible to do what i'm after? The formulae don't appear to be entered as array formula.

I'm confused and ultimately need an adult. I hope i'm making sense!!!!!

:oops:
 
Upvote 0
OK... i've been doing more investigation on this... i did have my output array set as Double. I changed this to Variant and now the MMULT bit works (in isolation). I started breaking the formula down into chunks to test each bit.

I've had success with
outputFlows(countCycle, countAttacks) = Application.MMult(baselinePoisson, fixedBaseline)

But when i try to add the EXP bit in i get a System13 error, i used...
outputFlows(countCycle, countAttacks) = Application.Exp(Application.MMult(baselinePoisson, fixedBaseline) ^ countAttacks)
 
Upvote 0
Sorted it.... shg gave me the pointer that i needed.

I sorted it by adding the (1) after the MMULT. So now it does this...

outputFlows(countCycle, countAttacks) = Exp(Application.MMult(baselinePoisson, fixedBaseline)(1)) ^ countAttacks

Clearly i have managed to bundle my way through this. Apologies for me spewing my thought process all over this thread. Thanks to all who have taken the time to offer assistance. You guys are the best!
 
Upvote 0

Forum statistics

Threads
1,214,629
Messages
6,120,630
Members
448,973
Latest member
ChristineC

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