Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类型不匹配vba二维数组_Vba_Excel - Fatal编程技术网

类型不匹配vba二维数组

类型不匹配vba二维数组,vba,excel,Vba,Excel,上面的代码起作用,它打印给定值的两列。比如说 strData = "{""INTEREST EARNING ASSETS"", """";" & _ """Interbank Placement"", ""goku"";" & _ """Corporate Bonds"", ""goku"";" & _ """Government Bonds and T-Bills"", ""goku"";" & _

上面的代码起作用,它打印给定值的两列。比如说

strData = "{""INTEREST EARNING ASSETS"", """";" & _
        """Interbank Placement"", ""goku"";" & _
        """Corporate Bonds"", ""goku"";" & _
        """Government Bonds and T-Bills"", ""goku"";" & _
        """Customer Loans"", ""cow"";" & _
        """"", ""soccer"";" & _
        """Customer Loans"", ""cow"";" & _
        """Customer Loans"", ""cow"";" & _
        """test"", 444444;" & _
        """drinks"", ""goal""}"

    varData = Evaluate(strData)

    For intCounter1 = 1 To UBound(varData, 1)
        For intCounter2 = 1 To UBound(varData, 2)
            ActiveCell.Value = varData(intCounter1, intCounter2)
            ActiveCell.Offset(0, 1).Select
        Next intCounter2
        ActiveCell.Offset(0, -2).Select
        ActiveCell.Offset(1, 0).Select
    Next intCounter1
等等

但是,当我在strData的第3行添加一个额外的行时,如下面所示,它表示类型不匹配。我真的不明白为什么?事实上,如果我在下面的任何一行加上一行,它会给我同样的错误。为什么会这样

INTEREST EARNING ASSETS *BLANK*
Interbank Placement      goku 
Corporate bonds          goku

使用
Range()直接分配表/数组的值。调整大小(n,m)。值=

strData = "{""INTEREST EARNING ASSETS"", """";" & _
            """Interbank Placement"", ""goku"";" & _
            """Interbank Placement"", ""goku"";" & _
            """Corporate Bonds"", ""goku"";" & _
            """Government Bonds and T-Bills"", ""goku"";" & _
            """Customer Loans"", ""cow"";" & _
            """"", ""soccer"";" & _
            """Customer Loans"", ""cow"";" & _
            """Customer Loans"", ""cow"";" & _
            """test"", 444444;" & _
            """drinks"", ""goal""}"

注:永远不需要使用select语句来赋值。只需选择正确的单元格引用,并直接使用它来读/写值。

Evaluatei上有255个字符的限制。我有没有办法绕过这个问题,向2D数组中添加更多值?感谢您可以使用较短的值。或者,解释一下你为什么这么做:这似乎不是一个有用的方法。以常规方式构造数组会更容易,或者可以从工作表中提取数组
Dim varData() as Variant
ReDim varData(1 to 4, 1 to 2)

varData(1,1) = "INTEREST EARNING ASSETS"
varData(1,2) = "*BLANK*"
varData(2,1) = "Interbank Placement"
varData(2,2) = 1.2344#
varData(3,1) = "Corporate bonds"
varData(3,2) = 1.04305#
varData(4,1) = "Customer Loans"
varData(4,2) = 1.10383#

ActiveCell.Resize(4,2).Value = varData