I want to remove predefined parts of the strings in the following table and save the values in an array. For some reason I get an error stating that I'm outside of the index. The lengths of the strings in the table can vary.
Sub New_1()
Dim i, j, k As Integer
Dim Endings As Variant
k = 0
Endings = Array("/A", "/BB", "/CCC", "/DDDD", "/EEEEE")
Dim ArrayValues() As Variant
With Worksheets("table1")
Dim lastRow As Long: lastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
ReDim ArrayValues(lastRow)
For i = lastRow To 1 Step -1
For j = 0 To UBound(Endings)
ArrayValues(k) = Replace(.Range("A" & i), Endings(j), "")
k = k + 1
Next j
Next i
End With
End Sub

for j ...loop is storing four items in sequential elements of ArrayValue for each entry on your worksheet. You probably only want to store a single value.k = k + 1after the loop ending withNext j. I suppose that you need a single value obtained by replacing of allEndingsarray elements. Is that supposition correct?Redim Preserve ArrayValues(k -1). To avoid having a last empty element. Depending on what you intend doing with the array, it may stay there, but usually is good to have an array without empty elements...