title: Scripting.Dictionary adding items without using Dictionary.Add - BUG?
body: <p>Scripting.Dictionary likes to add values for no reason, when you look a value up! Demonstrated with a 30 second example:</p>
  
  <p>Create a new worksheet, and fill in <code>A1:A4 = {1,2,3,4}</code></p>
  
  <p>Insert a new vba module and add this code</p>
  
  <pre><code>Public Sub test()
  
      Dim rowIndex As Integer
      '
      Dim dict As Scripting.Dictionary
      Set dict = New Scripting.Dictionary
  
      For rowIndex = 1 To 4
  
          dict.Add Trim(Sheet1.Cells(rowIndex, 1).Value), rowIndex
  
          Dim notEvenAddingSoWhyAreYouAdding As Variant
          notEvenAddingSoWhyAreYouAdding = dict(Sheet1.Cells(rowIndex, 1).Value)
  
      Next rowIndex
  
  End Sub
  </code></pre>
  
  <p>Put a breakpoint on <code>Next rowIndex</code></p>
  
  <p>Run the sub and inspect the value of <code>dict</code>. It now has two values, <code>"1"</code> and <code>1</code>, as you can see in the image below:</p>
  
  <p><a href="https://i.stack.imgur.com/1907W.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1907W.png" alt="enter image description here"></a></p>
  
  <p>What. The. Hell?!</p>
  
  <p>I realise I have the <code>Trim(...)</code> function in the <code>dict.Add()</code> line, which means there are two distinct keys in use, but why is it adding an extra value when it does a lookup?! That makes no sense whatsoever - now <code>dict.Count</code> would not give the value I would expect.</p>