[英]Type Mismatch Error in a simple VBA matrix code
Sub MacroTemp()
Dim i, j As Integer
Dim c(1, 1) As Double
For i = 0 To 1
For j = 0 To 1
c(i, j) = i + j
Sheets(Sheet2).Cells(i + 1, j + 1).Value = c(i, j)
Next j
Next i
End Sub
It is showing Type Mismatch Error.So what is wrong in this code?它显示类型不匹配错误。那么这段代码有什么问题?
It doesn't look like you are referencing Sheet2
correctly.看起来您没有正确引用Sheet2
。
If Sheet2
is the name of your worksheet, then you can reference it like so:如果Sheet2
是您的工作表的名称,那么您可以像这样引用它:
Sheets("Sheet2").Cells(i + 1, j + 1).Value = c(i, j)
Alternatively, if Sheet2
is the code name of the worksheet that you are referring to, you can use this:或者,如果Sheet2
是您所指的工作表的代码名称,则可以使用:
Sheet2.Cells(i + 1, j + 1).Value = c(i, j)
I am assuming you haven't declared a string variable Sheet2
anywhere.我假设您没有在任何地方声明字符串变量Sheet2
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.