Type Mismatch Error

elotromateo

New Member
Joined
May 19, 2010
Messages
42
I keep getting a type mismatch error when I try to round "z(1,1)". I don't understand this as the value is a numeric expression, even if it is a Variant type. Even if I get rid of the round, I still can't put it in a message box, despite asking for only the one value. I am completely at a loss for what to do here. I've tried converting the value and assigning it to a different variable, but that spit out the type mismatch error as well.

Any thoughts?


Code:
Option Base 1
Sub test()

Dim T As Double, RH As Double, z(1, 1) As Variant
Dim ArrayT(1, 1 To 4) As Variant
Dim ArrayV(1 To 4, 1 To 4) As Variant
Dim ArrayRH(1 To 4, 1) As Variant
Dim ArrayMult(1 To 4, 1) As Variant
Dim i As Integer, j As Integer

T = 85
RH = 60

With Sheets("Sheet2")
    For i = 1 To 4
        For j = 1 To 4
            ArrayV(i, j) = .Cells(i, j)
        Next
    Next
End With
                       
If T >= 80 Then
    For i = 1 To 4
        ArrayT(1, i) = (T) ^ (i - 1)
    Next
    For j = 1 To 4
        ArrayRH(j, 1) = (RH) ^ (j - 1)
    Next
    For i = 1 To 4
        ArrayMult(i, 1) = Application.MMult(ArrayV, ArrayRH)(i, 1)
    Next
    
    z(1, 1) = Application.MMult(ArrayT, ArrayMult)
    
    z(1, 1) = Round(z(1, 1), 1)
    
    Else
        z(1, 1) = T
End If

MsgBox z(1, 1)

End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Why are using an array for a single value?
 
Upvote 0
Whoops, just kind of kept the array theme going. Regardless, when I make z a single value, the type mismatch continues to occur.
 
Upvote 0
Have you checked the value after the MMulti calculation?
 
Upvote 0
If I pause the code right after the MMulti calc, then z does not have a value, not even an empty. Why would this happen?
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,261
Members
452,901
Latest member
LisaGo

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