title: VBA Excel 2010: Inserting values from dictionary into new row
body: <p>I'm having trouble with some VBA for Excel 2010. I have a list of names that have different serial numbers associated with them. The following code will look at a name in column A, look it up in the names dictionary for an array of serial numbers associated with this name, and print out each number in a new column.</p>
  
  <p>Names Dictionary:</p>
  
  <pre><code>Names("Jane B") = [111112, 22222]
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>|Joe A   | 11111
  |Jane B  | 111112|  22222 |
  |Jim C   | 11111 | 121212 | 1122112
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>Dim name, counter
  For i = 2 To Worksheets("Contacts").UsedRange.Rows.Count
    name = Worksheets("Contact").Cells(i, 1)
    counter = 0
    If names.Exists(name) Then
      For Each serial In names(name)
        Worksheets("Contact").Cells(i, 2+counter).Value = serial
        counter = counter + 1
      Next serial
    End If
  Next i
  </code></pre>
  
  <p>So far, so good. But the output format isn't good for inputting into Access. Instead, I'd like to have the following format:</p>
  
  <pre><code>|Joe A   | 11111
  |Jane B  | 111112
  |Jane B  | 22222
  |Jim C   | 11111
  |Jim C   | 121212
  |Jim C   | 1122112
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code>Dim name, counter
  For i = 2 To Worksheets("Contact").UsedRange.Rows.Count
    name= Worksheets("Contact").Cells(i, 1)
    counter = 0
    If names.Exists(name) Then
      For Each serial In names(name)
        Worksheets("Contact").Cells(i + counter, 2).Value = serial
        Worksheets("Contact").Cells(i + counter, 1).Value = name
        Worksheets("Contact").Cells(i + counter + 1, 1).EntireRow.Insert
        counter = counter + 1
      Next serial
    End If
  Next i
  </code></pre>
  
  <p>This is where I run into a problem. My output looks like this:</p>
  
  <pre><code>|Joe A   | 11111
  |Joe A   | 1700
  |Joe A   | 1700
  |Joe A   | 1700
  |Joe A   | 1700
  |Joe A   | 1700
  |Joe A   | 1700
  </code></pre>
  
  <p>While the numbers are all made up, the 1700 output is actually what is outputting, although that doesn't relate to any serial number (???). </p>
  
  <p>Can anyone spot what's off in my code?</p>
  
  <p>Thank you all for your time and consideration.</p>
  
  <p>With gratitude,</p>
  
  <p>Zac</p>