Excel VBA数组不从循环填充

这是代码。 我想要做的是创build一个数组包含一个string(名为“困难string”)的所有索引位置存在一些空格(string看起来像“文本文本文本…”):

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试图填充这个string,但实际上没有数字填充(当我拉cuttring(0),cutstring(1)等等什么都没有显示出来。

谁能帮忙? 非常感谢!!!!!!!

您需要在ReDim语句中使用“Preserve”命令,如引用的@ Gary的学生。 尝试:

 ReDim Preserve cutarray(UBound(cutarray) + 1)