I am trying to use Class properties Get
and Let
in a UserForm called UBidStatus
to fill a dictionary called DicOption
.
Everything works fine until the If Not DicOption(OptName).Exists
line (Error 404 object required).
NOTE: The code is working if I replace the whole code in the Public Property Let
by DicOption.Add key:=OptName, Item:=OptValue
.
This is the code in the Userform Class that I am trying to fix.
'Userform Class Module
Private DicOption As scripting.Dictionary
Public Property Get ProjectOption(ByVal OptName As String) As String
ProjectOption = UBidStatus.ProjectOption(OptName)
End Property
Public Property Let ProjectOption(ByVal OptName As String, ByVal OptValue As String)
If Not DicOption(OptName).Exists Then
DicOption.Add key:=OptName, Item:=OptValue
Else
DicOption(OptName) = OptValue
End If
End Property
Public Sub UserForm_Initialize()
Set DicOption = New scripting.Dictionary
End Sub
Private Sub UserForm_Terminate()
Set DicOption = Nothing
End Sub
Public Sub ExchangeToDicOption()
Dim LR As Long
Dim Rg As Range
Dim ws As Worksheet
Dim i As Long
Dim a As String
Dim b As String
Set ws = ActiveWorkbook.Worksheets(2)
Set Rg = ws.Columns(2)
DicOption.RemoveAll
LR = Rg.Find(What:="*", Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, MatchCase:=False).Row
If LR > 1 Then
For i = 2 To LR
a = Cells(i, 1)
b = Cells(i, 2)
UBidStatus.ProjectOption(a) = b
Next i
End If
End Sub