title: VBA dictionary not assigning value to key
body: <p>I created a function getField that looks through the second column and third column of a spreadsheet and returns a dictionary with the keys being the second column and the values being the third. The function takes in a string that is the field name that is being looked for but right now I can't assign a value to the key. Here's the line I'm referring to which currently works but the value is empty my attempt to assign the value failed so I put it in a comment to show you all what I tried. <code>If InStr(data(r, 1), fieldName) &gt; 0 Then dict(data(r, 1)) = Empty 'dict(value(r, 1))</code> </p>
  
  <p>Here's the rest of the code:</p>
  
  <pre><code>Public Function getField(fieldName As String)
  
      Dim data(), dict As Object, r As Long
      Set dict = CreateObject("Scripting.Dictionary")
  
      data = ThisWorkbook.Worksheets("Sheet1").UsedRange.Columns(2).value
      value = ThisWorkbook.Worksheets("Sheet1").UsedRange.Columns(3).value
  
      For r = 1 To UBound(data)
  
          If InStr(data(r, 1), fieldName) &gt; 0 Then dict(data(r, 1)) = Empty 'dict(value(r, 1))
       Next
  
      data = WorksheetFunction.Transpose(dict.Keys())
  
      Set getField = dict
  
  End Function
  </code></pre>