title: VBA - Combine several cells into a single string in Excel
body: <p>I'm working on a spreadsheet full of warranty data and there are three adjacent columns where different members of the service team can enter comments and trouble codes they find. I'm writing a macro to parse the comments looking for the trouble codes and I can get it to search one column fine, but I can't seem to get it to search adjacent columns in one step.</p>
  
  <p>My goal is to combine the three adjacent cells into a single string. I don't care about space or comma delimiters, the regex will still work, I just want the text of several adjacent cells combined into a single string which I will then pass to the regex. Here's what I have so far:</p>
  
  <pre><code>    'set regex input; if searching more than one column, combine into single string
      If ColNum &gt; 0 Then
          For m = 0 To ColNum - 1
              strInput = strInput &amp; Cells(i, ReadCol + m).Value
          Next
      Else
          strInput = Cells(i, ReadCol).Value
      End If
  </code></pre>
  
  <p>Where ReadCol is the starting column to search, ColNum is the number of adjacent columns to search (ColNum = 0 will only search the first column), i is the row iterator (each row is one warranty record), and strInput is what gets passed to regex. If I'm only searching one column, the macro works perfectly. If I try to search more than one, it throws a type mismatch error. Any help is appreciated!</p>