我正在编写一个程序来解析一个大型文本文件,其中包含多个非常长的数组,这些数组使用逗号分隔保存在一行中。
<valueslist list="-213.054,-200.3051,-193.7893,-185.3383,-186.351,-186.797,-185.2577,...
我正在使用 split 函数尝试将其分解,但是当我尝试执行程序时,它会抛出运行时错误 1004“应用程序定义或对象定义的错误
If InStr(Text, "<valueslist list=") <> 0 Then
Column = 5
Text = Replace(Text, "<valueslist list=" & Chr(34), "")
Text = Replace(Text, Chr(34) & "/>", "")
wrdArray = Split(Text, ",")
For i = 0 To UBound(wrdArray)
Cells(Row, Column).Value = wrdArray(i)
Column = Column + 1
Next i
Row = Row + 1
End If
当我尝试调试时,它需要我
Cells(row, column).Value = wrdArray(i)
我在一个循环中有这段代码,但是当我尝试解析的数组变得大量时,它在我的文件中大约死了一半
最佳答案
这更像是一份事后报告:P
I have this code inside a loop but it dies about half way through my file when the arrays that I'm trying to parse become massve
由于它变得庞大,因此您的代码可能会尝试写入 Excel 中不存在的列。
如果您使用的是 Excel 2003
,则只能写入 256
列,如果您使用的是 Excel 2007+
,则限制为增加到16384
。
检查是否达到限制的最佳方法是调试行 UBound(wrdArray)
OP 最终检查并确认阵列当时的大小为 32k。
关于arrays - 当我尝试将元素放入单元格时,为什么我的分割数组会抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30512006/