Hi. I have this function that is supposed to delete the element of an array at a required index. All input arrays start from 1 and are 2-dimensional. However, at the ReDim stage, it gives me an error that says subscript out of range. I can't seem to figure out what is wrong with the code.
Sub DeleteElementAt(ByVal index As Integer, ByRef required_array As Variant)
Dim i As Integer
' Move all element back one position
For i = index + 1 To UBound(required_array)
required_array(i - 1, 1) = required_array(i, 1)
Next
required_array(i - 1, 1) = -1
ReDim Preserve required_array(1 To i - 2, 1)
End Sub
Sub DeleteElementAt(ByVal index As Integer, ByRef required_array As Variant)
Dim i As Integer
' Move all element back one position
For i = index + 1 To UBound(required_array)
required_array(i - 1, 1) = required_array(i, 1)
Next
required_array(i - 1, 1) = -1
ReDim Preserve required_array(1 To i - 2, 1)
End Sub