title: Merge cells using vba based on a value
body: <p>I have columns J through X in my excel spreadsheet with the following values:</p>
  
  <pre><code>J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X
  1   1   1   1   1   2   2   2   2   2   2   2   3   3   3   
  </code></pre>
  
  <p>Where the values are variables themselves and can change.  For example the values can also be:</p>
  
  <pre><code>J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X
  1   2   2   2   2   2   2   2   3   3   3   3   3   3   3
  </code></pre>
  
  <p>I am trying to write a vba that will merge all cells (to the right) with values 1, 2, 3, etc.  Any help would be appreciated.  </p>
  
  <p>The result for example 1 would be:  Columns J through N would have merged as 1.  Columns O through U would have merged as 2.  Columns V through X would merge to 3.  See below</p>
  
  <pre><code>J                   O                           V       
  1                   2                           3           
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>I found an answer elsewhere.  I'll leave it here in case anyone is interested</p>
  
  <pre><code>   Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  
      Dim rngMerge As Range, cell As Range
      Set rngMerge = Range("J5:X5") 'Set the range limits here
  
  MergeAgain:
      For Each cell In rngMerge
          If cell.Value = cell.Offset(0, 1).Value And IsEmpty(cell) = False Then
              Range(cell, cell.Offset(0, 1)).Merge
              GoTo MergeAgain
          End If
      Next
  </code></pre>