title: Excel VBA merging cells in a function
body: <p>I wrote a crude function to select and concatenate cells based on a range.</p>
  
  <pre><code>Function GetSkills(CellRef As String, CellRefEnd As String, Delimiter As String)
  
      Dim CellStart As Range
      Dim CellEnd As Range
      Dim LoopVar As Long
      Dim StartRow As Long
      Dim EndRow As Long
      Dim Concat As String
      Dim Col As Long
  
      Set CellStart = Worksheets(1).Cells.Range("B" &amp; CellRef)
      Set CellEnd = Worksheets(1).Cells.Range("B" &amp; CellRefEnd)
  
      Col = CellStart.Column
      StartRow = CellStart.Row
      EndRow = CellEnd.Row
  
      With Range(CellStart, CellEnd)
          .Merge
          .WrapText = True
      End With
  
      Concat = ""
  
      For LoopVar = StartRow To EndRow
          Concat = Concat &amp; Cells(LoopVar, Col).Value
          If LoopVar &lt;&gt; EndRow Then Concat = Concat &amp; Delimiter &amp; " "
      Next LoopVar
  
      GetSkills = Concat
  
  End Function
  </code></pre>
  
  <p>Within it I'm trying to merge the cells, when I run the function I get a prompt saying: </p>
  
  <blockquote>
    <p>The selection contains multiple data values. Merging into once cell
    will keep the upper-left most data only</p>
  </blockquote>
  
  <p>I click OK and Excel crashes, restarts, and prompts the dialog again. Is there another way to merge a block of cells using VBA?</p>