1

I'm using Excel 2013.

I have a class called clsFund. It has one property of type string() called CompanyNames.

 private pCoName() as string

 Public Property Get CompanyNames() As String()
    CompanyNames = pCoName
 End Property

In a standard module I try to retrieve this string array but without any luck. I have the code below. The funny thing is the ubound tells me the correct answer of 10 but it doesn't like the line below clsData.PnL, the method is just expecting a string argument which I belive I have supplied however I get a compile error: wrong number of arguments or invalid property assignment - I do not understand?

 Private Sub PrintCompanyNameAndPnL()

 Dim i As Integer

 For i = 1 To UBound(Fund.BloombergIndices)
     Range("A" & i) = clsData.PnL(Fund.CompanyNames(i))                    
 Next i

End Sub

2 Answers 2

1

If you write it that way, you are passing i as a parameter to the CompanyNames property, which doesn't accept any arguments.

You need to access the array items like this:

Range("A" & i) = clsData.PnL(Fund.CompanyNames()(i)) 

so you are returning the array and then passing i as an index to that.

Sign up to request clarification or add additional context in comments.

Comments

1

You return a full array, so you need an extra set of parens to address the elements:

Range("A" & i) = clsData.PnL(Fund.CompanyNames()(i))  

Or change to

Public Property Get CompanyName(index As Integer) As String
   CompanyName = pCoName(index)
End Property

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.