Question

I would like to remove a specific item from a collection, then add a different value to its place.

For example:

Sub test()

Dim col As Collection
Set col = New Collection

col.Add (10)
col.Add (20)
col.Add (30)
col.Add (40)
col.Add (50)

col.Remove (3)
col.Add ("x", ,3) 'error here

End Sub

When I write the col.Add line it says Compile error, expected: = If I just write

col.Add ("x")

it works just fine, but it puts the value to the end not being the place defined.

It may be trivial, thanks for the help!

Was it helpful?

Solution

Simply lose the parentheses;

col.Add "x", , 3

For

10
20 
"x"

("x") works as the parens are not part of the call to add rather they mean evaluate "x" so are valid (but unnecessary) for any single value which is then passed to .add.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top