【发布时间】:2015-05-26 15:27:15
【问题描述】:
这里是代码。我要做的是创建一个数组,其中包含存在一些空格的字符串(名为“difficultstring”)的所有索引位置(字符串看起来像“text text text ...”):
Dim cutarray
cutarray = Array(0)
For spacething = 2 To Len(difficultstring)
If Mid(difficultstring, spacething, 1) = " " And Mid(difficultstring, spacething - 1, 1) <> " " Then
ReDim cutarray(UBound(cutarray) + 1)
cutarray(UBound(cutarray)) = spacething
End If
Next spacething
但由于某种原因,当我尝试使用 cutarray 数组稍后执行某些操作或显示来自 cutarray 的值时,它看起来好像没有任何数字。我检查了 len(cutstring),它返回的值是 43——这意味着 Excel 试图填充这个字符串,但实际上没有填充数字(当我拉出 cutstring(0)、cutstring(1) 等时,什么都没有显示。
有人可以帮忙吗?非常感谢!!!!!!!
【问题讨论】:
-
考虑使用 Preserve 选项
-
将
ReDim更改为Redim Preserve。