从VBA中构build和命名的数组构build一个数据透视表
我试图引用我的枢轴的源数据名称。 我有以下代码:
Set rng1 = Sheets("CALA current credit usage").Range("A1:L235") Set rng2 = Sheets("CALA forecast credit usage").Range("A2:L235") Dim MyArray() TotalRows = rng1.Rows.Count + rng2.Rows.Count + 1 ReDim Preserve MyArray(1 To TotalRows, 1 To rng1.Columns.Count) For i = 1 To rng1.Columns.Count For j = 1 To rng1.Rows.Count MyArray(j, i) = rng1.Cells(j, i) Next j Next i j = j - 1 '''''' For h = 1 To rng2.Columns.Count For w = 1 To rng2.Rows.Count MyArray(w + j, h) = rng2.Cells(w, h) Next w Next h ActiveWorkbook.Names.Add Name:="ResultingRange", RefersTo:=MyArray
但是当我把枢轴链接到ResultingRange我得到:
数据源引用无效。
有任何想法吗?