Well, the arrays in VBA do not have such a Remove property...
The arrays field is large and rather complicated. In the next code I will try explaining how you can remove elements from 1D arrays without iteration.
You will see each code sequence return in Immediate Window. It can be seen pressing Ctrl + G, being in Visual Basic for Application Editor (VBE):
Sub PlayWith1DArrays()
Dim arr, i As Long
ReDim arr(5) '(0 To 5) = 6 elements...
For i = 0 To 5
arr(i) = i
Next i
Debug.Print Join(arr, "|") 'just tp see the loaded aray
arr = filter(arr, 1, False) 'remove the 1 element
Debug.Print Join(arr, "|") 'it returns 0|2|3|4|5
'But loading the array in a similar way, WITH MORE ELEMENTS,
'making it to load MORE elements CONTAINING 1:
ReDim arr(1 To 15)
For i = 1 To UBound(arr)
arr(i) = i
Next i
Debug.Print Join(arr, "|") 'the loaded array
arr = filter(arr, 1, False)
Debug.Print Join(arr, "|") 'it returns 2|3|4|5|6|7|8|9
'it performs a textual comparison...
'removing elements containing 1 character.
'But you can use a TRICK to remove the EXACT (string) element:
ReDim arr(1 To 15)
For i = 1 To UBound(arr)
arr(i) = "arr " & i
Next i
Debug.Print Join(arr, "|") 'the loaded array by iteration
Dim elToRemove As String: elToRemove = "Arr 1" 'the element to be removed (no case sensitive...)
Dim mtch
Const strangeString As String = "xx$_$##" 'a strimg extremely improbable to be
'contained by that array elements
mtch = Application.match(elToRemove, arr, 0)
If IsNumeric(mtch) Then 'if it exists in the array
arr(mtch) = strangeString
arr = filter(arr, strangeString, False)
End If
Debug.Print Join(arr, "|") 'it returns the array without its first element...
'arr 2|arr 3|arr 4|arr 5|arr 6|arr 7|arr 8|arr 9|arr 10|arr 11|arr 12|arr 13|arr 14|arr 15
'ReDim arr(1 To 15)...
'But this is happening when the LBound of the array is 1...
'Otherwise, you need to check it and adapt:
ReDim arr(14) ' (0 to 14)...
For i = LBound(arr) To UBound(arr)
arr(i) = "arr " & i
Next i
Debug.Print Join(arr, "|") 'the loaded array by iteration
Debug.Print "LBound of arr = " & LBound(arr) 'LBound of the array declared as ReDim arr(14) is zero...
mtch = Application.match(elToRemove, arr, 0)
If IsNumeric(mtch) Then 'if it exists in the array
arr(IIf(LBound(arr) = 0, mtch - 1, 1)) = strangeString 'match returns 1 for the first array element
'in a 1D array, without Option Base 1 or without
'ReDim with LBound different than 0, is zero!
arr = filter(arr, strangeString, False)
End If
Debug.Print Join(arr, "|") 'it returns the array without its second element...
'arr 0|arr 2|arr 3|arr 4|arr 5|arr 6|arr 7|arr 8|arr 9|arr 10|arr 11|arr 12|arr 13|arr 14
'A 2D array with a single column and a single row can be easily transformed in a 1D type and use the above
'explained rules:
ReDim arr(1 To 11, 1 To 1) 'a single column...
For i = 1 To UBound(arr)
arr(i, 1) = "arr " & i
Next i
arr = Application.Transpose(arr) 'transform it in 1D array by transposing...
Debug.Print Join(arr, "|") 'the loaded array by iteration
ReDim arr(1 To 1, 1 To 11) 'a single row...
For i = 1 To UBound(arr, 2) 'the columns number
arr(1, i) = "arr " & i
Next i
arr = Application.Transpose(Application.Transpose(arr)) 'transform it in 1D array by DOUBLE transposing...
Debug.Print Join(arr, "|") 'the loaded array by iteration
'proceed as above to filter it...
End Sub
I used Join function only to visually see the processing/filtering/removing return against the array loaded by iteration...
In the 2D arrays it is much more complicated to filter elements by rows or by columns... Basically, it can be done by iteration.
If something is not clear enough, please do not hesitate to specifically ask for clarifications.
Please, send some feedback after testing it.
Removemethod on an arrary - see stackoverflow.com/questions/7000334/…