title: Excel VBA - Loop through column one at a time
body: <p>I am trying to loop through each row in <code>Sht1 (B2:B138)</code>, and set an "input" cell <code>Sht2 (A1)</code> to each item in that loop, one at a time.  Then, the value in an "output" cell <code>Sht2 (N7)</code> would be copied back to <code>Sht1 (C2:C138)</code>.  </p>
  
  <hr>
  
  <p>So for example:</p>
  
  <p><code>Sht2 (A1) = value in Sht1 (B2)</code>, then
  <code>Sht1 (C2) = value in Sht2 (N7)</code></p>
  
  <p>Repeat</p>
  
  <p><code>Sht2 (A1) = value in Sht1 (B3)</code>, then
  <code>Sht1 (C3) = value in Sht2 (N7)</code></p>
  
  <hr>
  
  <p>Over and over until it reaches the bottom of the list.  Eventually I may have to expand the list in <code>Sht1 ColB</code> and so I have been trying to have it evaluate the number of iterations needed dynamically.</p>
  
  <p>The code I'm trying below gives me all the correct "outputs" but they do not end up in the correct cell in <code>Sht2 ColC</code>. Please see below.  I researched and found <a href="https://stackoverflow.com/questions/20805874/excel-vba-copy-and-paste-loop-within-loop">this Q/A</a> to be helpful and used it to influence the code.  I appreciate your help in advance.  <a href="https://drive.google.com/file/d/0B38YKIZO_lcKVW5FNVBMa2hibzA/view?usp=sharing" rel="nofollow noreferrer">My workbook</a> in case you need to see it.</p>
  
  <pre><code>Sub fnDescCalc()
  'Define the objects
  
  Dim wb As Workbook
  Dim Framework As Worksheet
  Dim SumFramework As Worksheet
  Dim colB As Long
  Dim colC As Long
  Dim LastcolC As Integer
  Dim LastcolB As Long
  
  'Set the Variables
  Set wb = ThisWorkbook
  Set Framework = wb.Sheets("Framework")
  Set SumFramework = wb.Sheets("Sum_Framework")
  
  LastRowcb = Framework.Range("B:B").Find("*", searchdirection:=xlPrevious).Row
  colB = 2
  
  LastcolC = 138
  
  'This is the beginning of the main loop
  For colC = 2 To LastcolC
  
  'This is the beginning of the nested loop
      For colB = 2 To LastcolB
      SumFramework.Range("A1") = Framework.Range("B" &amp; colB).Value
      colB = colB + 1
  
  Framework.Range("C" &amp; colC) = SumFramework.Range("N7").Value
  colC = colC + 1
  
  Next colB
  
  Next colC
  
  End Sub
  </code></pre>