Grha Gandana P
Grha Gandana P

Reputation: 5

Arithmetic Operation for Variant Data Type in VBA


Public Sub MMULT()

Dim temp As Variant
Dim total As Double
Dim a, b As Range
Dim i As Integer

total = 0.45

For i = 1 To 9
Set a = Range(Cells(i + 15, 3), Cells(i + 15, 11))
Set b = Range(Cells(16, 14), Cells(24, 14))
temp = Application.WorksheetFunction.MMULT(a, b)
total = total + temp
Next i

Range("M9").Select
Range("M9").Value = total

End Sub

Hi, can someone help me to overcome the error? i got a message box "Type mismatch" in line 14 that contain the code: total = total + temp. i have tried several changes like turn all the data type of variables in to variant, but it's still give the same error. Thanks

Upvotes: 0

Views: 285

Answers (1)

Tim Williams
Tim Williams

Reputation: 166316

MMULT returns an array (even when only a single value is returned) - you can't add a Double and an array.

total = total + temp(1)

Upvotes: 1

Related Questions