문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top