I am trying to add a variable number of items to a string array.
My code is in a worksheet change function:
Dim StartNums(0 To 2) As String
doneColor = RGB(175, 175, 175)
cmt = FRg.Comment.Text
rowLen = InStr(1, cmt, vbLf)
If rowLen = 0 Then
rowLen = Len(cmt)
End If
numChunks = rowLen / 32
numRows = Len(cmt) / rowLen
' For i = 1 To 12 'FRg.Comment.Shape.TextFrame.Characters.Count
' With FRg.Comment.Shape.TextFrame.Characters(i, 1)
' If .Font.Strikethrough = True Then
' .Font.Color = vbGreen
' End If
' End With
' Next i
MsgBox ("About to fill StartNums, nothing should be in it yet")
For j = 0 To numChunks - 1
MsgBox ("going to add stuff for chunk " & j)
If Not UBound(StartNums) = 2 Then
' MsgBox ("resizing an empty array")
' ReDim Preserve StartNums(3) As Variant
' Else
'MsgBox ("resizing a non-empty array")
ReDim Preserve StartNums(UBound(StartNums) + 3) As String
End If
StartNums(UBound(StartNums) - 2) = (j * 32) + 5 + (0 * 9)
StartNums(UBound(StartNums) - 1) = (j * 32) + 5 + (1 * 9)
StartNums(UBound(StartNums) - 0) = (j * 32) + 5 + (2 * 9)
Next j
Now whenever I go into the worksheet, the ReDim line has a Compile Error Array already dimensioned. I'm aware it's already dimensioned, which is why I'm ReDim-ing it.
How do I add 3 more spaces in an array?