1

I am having an issue with the below code. Whenever it gets to the last line, it throws the error "Argument Not Optional", and will not compile. I have no clue what argument it is talking about.

Option Base 1
Dim temp As New ProductionItem 'Production Item is a class that I made
Dim Arr() As Collection
ReDim Arr(5)
Dim coll As New Collection
coll.Add temp
Arr(1) = coll
2
  • 4
    A Collection is an object. If you want to set Arr(1) to be the collection coll, you will need to Set Arr(1) = coll. (But are you really intending Arr to be an array of Collections of ProductionItem?) Commented Apr 11, 2017 at 22:45
  • And the missing argument it is talking about is the key, because without the Set keyword, VBA was trying to invoke the default property of the Collection object, that is, col1.Item(key) where the parameter key is mandatory... Commented Apr 11, 2017 at 23:24

1 Answer 1

1

Only need Set

Option Base 1

Sub fun()
    Dim Arr() As Collection
    ReDim Arr(5)
    Dim coll As New Collection
    coll.Add 1
    Set Arr(1) = coll
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.