数组值不转置给单元格

我正试图学习如何在Excel VBA中使用字典。 testing是通过一个数组将字段A中1-100000行的所有值传递给一个字典,然后将所有值写入列B.这个工作正常,直到行34464,B列中的其余行得到#N/A

任何想法为什么?

 Sub nnn() 'Tools - References - Microsoft Scripting Runtime Dim myArray As Variant Dim myRow As Long Dim dicMyDictionary As Scripting.Dictionary Set dicMyDictionary = New Scripting.Dictionary With ThisWorkbook.Worksheets("Sheet1") myArray = Range(Cells(1, 1), Cells(100000, 1)).Value For myRow = LBound(myArray, 1) To UBound(myArray, 1) dicMyDictionary.Add myRow, myArray(myRow, 1) Next myRow myArray = dicMyDictionary.Items .Range("B1").Resize(dicMyDictionary.Count, 1).Value = Application.Transpose(myArray) Set dicMyDictionary = Nothing End With End Sub 

由于工作表Transpose的限制(请参阅Paul Bica发布的链接),您需要直接将元素指定给数组。 以下应该工作:

 Option Explicit Sub nnn() 'Tools - References - Microsoft Scripting Runtime Dim myArray As Variant Dim myRow As Long Dim dicMyDictionary As Scripting.Dictionary Set dicMyDictionary = New Scripting.Dictionary With ThisWorkbook.Worksheets("Sheet1") myArray = Range(Cells(1, 1), Cells(100000, 1)).Value For myRow = LBound(myArray, 1) To UBound(myArray, 1) dicMyDictionary.Add myRow, myArray(myRow, 1) Next myRow ReDim myArray(1 To dicMyDictionary.Count, 1 To 1) For myRow = 1 To UBound(myArray, 1) myArray(myRow, 1) = dicMyDictionary(myRow) Next myRow .Range("B1").Resize(dicMyDictionary.Count, 1).Value = myArray Set dicMyDictionary = Nothing End With End Sub