title: VBA code to insert blank rows doesn't always work
body: <p>I'm trying to insert a blank row between 2 rows if the values in A1 &lt;> A2.  I was given the code below and it works if the data looks like this <code>a,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h,i,i</code>.  The results are exactly what I'm looking for: a, blank row, a, blank row, b blank row, b, blank row, c, blank row, c, etc.</p>
  
  <p>However, if the data looks like this <code>a,b,c,d,e,f,g,h,i</code> then I get 8 blank rows between a and b but none anywhere else.</p>
  
  <p>Any ideas why this is happening like this?</p>
  
  <hr>
  
  <pre><code>Sub Social_Distance()
  
  Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet2")
  
  Dim lr As Long, MyUnion As Range, xCell As Range
  lr = ws.Range("A" &amp; ws.Rows.Count).End(xlUp).Row
  
  For Each xCell In ws.Range("A2:A" &amp; lr)
      If xCell.Value &lt;&gt; xCell.Offset(1).Value Then
          If Not MyUnion Is Nothing Then
              Set MyUnion = Union(MyUnion, xCell.Offset(1))
          Else
              Set MyUnion = xCell.Offset(1)
          End If
      End If
  Next xCell
  
  If Not MyUnion Is Nothing Then MyUnion.EntireRow.Insert Shift:=xlDown
  
  End Sub
  </code></pre>