Excel 将数组粘贴到单元格中(将单元格大小调整为数组维度后)
Excel pasting array in cell (after resizing cell to array dimensions)
我想从一个单元格上粘贴一个二维数组,使用 RESIZE() 将范围扩展到数组的确切大小。
我得到一个
运行 错误类型 13
类型不匹配
ReDim conceptArray(1 To 5, NumberOfConcepts + 1)
Dim firstcellofTbl As range
Set firstcellofTbl = qbaTbl.ListColumns("name").range.iTem(1).Offset(1, 0)
' this is just a test:
'firstcelloftbl is a single cell
firstcellofTbl.Select
firstcellofTbl.Resize(UBound(conceptArray, 2), UBound(conceptArray, 1)) = Application.Transpose(conceptArray)
无论数组的大小如何,有些东西我认为是理所当然的。
a) firstcellofTbl 只是一个单元格。并且在选择生效后就存在。
调整大小与数组的维度相同,因为它只是调整到数组的维度
c) 调整大小互换了两个维度,因此 application.transpose
这是我添加的用于测试的代码:
MsgBox UBound(conceptArray, 1)
MsgBox UBound(conceptArray, 2)
Dim newrange As range
Set newrange = firstcellofTbl.Resize(UBound(conceptArray, 2), UBound(conceptArray, 1))
MsgBox newrange.address
是:
UBound(conceptArray, 1)=5
UBound(conceptArray, 2)=439
newrange.address =$a:$E1
这似乎是匹配的,因为新范围的大小与转置数组相同
我可能做错了什么?
非常感谢
注意:
使用这种将数据粘贴到列表对象(或 sheet)的方式比使用 for 循环填充快数百万倍,这就是使用它的原因。
问题是数组的尺寸是变体。
原文:
dim conceptarray() as variant
解决方案:
dim conceptarray() as string
我想从一个单元格上粘贴一个二维数组,使用 RESIZE() 将范围扩展到数组的确切大小。
我得到一个 运行 错误类型 13 类型不匹配
ReDim conceptArray(1 To 5, NumberOfConcepts + 1)
Dim firstcellofTbl As range
Set firstcellofTbl = qbaTbl.ListColumns("name").range.iTem(1).Offset(1, 0)
' this is just a test:
'firstcelloftbl is a single cell
firstcellofTbl.Select
firstcellofTbl.Resize(UBound(conceptArray, 2), UBound(conceptArray, 1)) = Application.Transpose(conceptArray)
无论数组的大小如何,有些东西我认为是理所当然的。 a) firstcellofTbl 只是一个单元格。并且在选择生效后就存在。
调整大小与数组的维度相同,因为它只是调整到数组的维度
c) 调整大小互换了两个维度,因此 application.transpose
这是我添加的用于测试的代码:
MsgBox UBound(conceptArray, 1)
MsgBox UBound(conceptArray, 2)
Dim newrange As range
Set newrange = firstcellofTbl.Resize(UBound(conceptArray, 2), UBound(conceptArray, 1))
MsgBox newrange.address
是: UBound(conceptArray, 1)=5 UBound(conceptArray, 2)=439
newrange.address =$a:$E1
这似乎是匹配的,因为新范围的大小与转置数组相同
我可能做错了什么? 非常感谢
注意: 使用这种将数据粘贴到列表对象(或 sheet)的方式比使用 for 循环填充快数百万倍,这就是使用它的原因。
问题是数组的尺寸是变体。
原文:
dim conceptarray() as variant
解决方案:
dim conceptarray() as string