Home » excel » excel – Dictionary compile error: method or data member not found

excel – Dictionary compile error: method or data member not found

Posted by: admin May 14, 2020 Leave a comment

Questions:

Not sure why getting the above error. I have a class module named clsRemit with code:

Sub clsRemit()

Public vendor As String
Public amount As Long
Public invoices As String

End Sub

Then in my module, I have:

For Each v In dictlist.Keys
    If InStr(1, .Cells(q, "B").Value2, v, vbTextCompare) Then
        vendor = .Cells(q, "B").Value2

        If dict.Exists(vendor) = True Then
            Set oVend = dict(vendor)
        Else
            Set oVend = New clsRemit
            dict.Add vendor, oVend
        End If

        oVend.vendor = vendor 'error here
        oVend.invoices = oVend.invoices & vbCrLf & .Cells(q, "F")
        oVend.amount = oVend.amount + .Cells(q, "G").Value
    End If
Next
How to&Answers:
oVend.vendor = vendor 'error here

That’s a red herring. The real problem is here:

Sub clsRemit()

Public vendor As String
Public amount As Long
Public invoices As String

End Sub

Public (or Private, for that matter) is illegal in a procedure scope. Remove the procedure scope, the code should compile:

Option Explicit
Public vendor As String
Public amount As Long
Public invoices As String