I'm trying to write a function that searches a certain column (Call it Column A) for the term "Request". Once this row is found it searches another column (Call it Column B) in the same row for a unique term. The goal is to count how many unique terms in Column B correspond to the term "Request" in column A. The way I've tried to do this is by creating a dictionary and adding a term to it if that term does not already exist in the dictionary. The program counts how many terms are added to the dictionary so I know how many unique terms there are. However, the code I have now just keeps adding every term to the dictionary, regardless of whether or not the term already exists or not. I've been trying to figure it out for a while now and can't quite figure it out. Here's the code:
j = 0
For i = 1 To LastRow
If Cells(i, 13).Value Like "Request" Then
Set dic = CreateObject("Scripting.Dictionary")
If Not dic.exists(Cells(i, 13)) Then
ucount = ucount + 1
dic.Add j, Cells(i, 13)
j = j + 1
End If
End If
Next i
I think the issue might lie with the dic.Add feature, but I'm not sure. I'm relatively new to VBA and coding in general.
Addparameters arekey,value- theExistsmethod checks the key, not the value, and you're addingjas the key when you add an item. Also you have no wildcards in yourLikecomparison, so it will only find the exact value "Request" - maybe you meant "Request" ?