title: VBA - iterating over column names
body: <p>I am doing the same type of operation across multiple columns. For example, my code currently works when I do this:</p>
  
  <pre><code>Cells(lRow, "D") = Cells(lRow, "D") + Cells(lRow + 1, "D")
  Cells(lRow, "E") = Cells(lRow, "E") + Cells(lRow + 1, "E")
  ' .... '
  Cells(lRow, "AA") = Cells(lRow, "AA") + Cells(lRow + 1, "AA")
  Cells(lRow, "AB") = Cells(lRow, "AB") + Cells(lRow + 1, "AB")
  </code></pre>
  
  <p>In the code above, I am going from column D to column AB and at each column am adding the value of the current row I'm looking at with the value of the row below it. The result code is almost 30 lines long and it's mostly copy and pasted which is just nasty. </p>
  
  <p>I am trying to refactor this code so that I can factor out the column name (the second argument in the Cells function call). I was thinking of using a for loop, iterating from column "D" to column "AB" and performing the addition operation. </p>
  
  <pre><code>' iterate from column D to column AB and at each column do the operation below ' 
  For c = "D" To "AB"
      Cells(lRow, c) = Cells(lRow, c) + Cells(lRow + 1, c)
  Next c
  </code></pre>
  
  <p>This doesn't work because it seems VBA does not allow iteration (for loop) over characters (going from "D" to "AB"). </p>
  
  <p>I've seen other solutions involving integers and converting them to characters (A = 1, B = 2, C = 3, D = 4, etc.) but couldn't get that working. I think that looks something like this:</p>
  
  <pre><code>' integer to character mapping: A = 1, B = 2, C = 3, D = 4, ... , AA = 27, AB = 28 '
  For i = 4 To 28
      colNameFromInt = Chr(ascii)
      Cells(lRow, colNameFromInt) = Cells(lRow, colNameFromInt) + Cells(lRow + 1, colNameFromInt)
  Next i
  </code></pre>
  
  <p>In short, if I showed you the ~30 lines of code from the top, how would you condense it?</p>
  
  <p>Thanks!</p>