title: How to paste values from a variable into a column
body: <p>I needed to write some code that would select the minimum of blocks of cells that correspond to equal cell values across rows in another column.  Here's what I have:</p>
  
  <pre><code>Function MoveDown(c)
      MoveDown = c.Offset(0, 1).Select
  End Function
  
  Sub LoanOptimization()
      For Each c In Worksheets("Sheet1").Range("C1:C65536").Cells
          c1 = c.Row
          Do While c.Value = MoveDown(c).Value
              c = MoveDown(c)
              c2 = MoveDown(c).Row
              Set CellRange = ActiveSheet.Range(Cells(c1, 12), Cells(c2, 12)).Select
              Minimum = Application.WorksheetFunction.Min(CellRange)
          Loop
      Next
      Range("N3").Select
      ActiveSheet.Paste
  End Sub
  </code></pre>
  
  <ol>
  <li>Does this even make sense for what I'm trying to do, and </li>
  <li>How do I paste the values from my Minimum variable into another column</li>
  </ol>
  
  <p>EDIT:</p>
  
  <p>I changed and added to my code, because my first question was just the first step in what I needed to do.  Here is what I have, but I keep getting compile errors:</p>
  
  <pre><code>Dim lastRow As Integer
  Dim i As Integer
  Dim comp1 As Integer
  Dim comp2 As Integer
  Dim rngCount As Integer
  Dim minimum As Integer
  Dim comp3 As Integer
  Dim comp4 As Integer
  
  lastRowDate = WorksheetFunction.CountA(Range("G:G")) 'Find the last row with data
  lastRowNotional = WorksheetFunction.CountA(Range("L:L"))
  rngCount = 0
  
  For i = 1 To lastRowDate
      comp1 = ActiveSheet.Cells(i, 7).Value 'Set comp1 equal to the Value of the cell in         Column C at the current row in the For loop
      comp2 = ActiveSheet.Cells(i + 1, 7).Value 'Set comp2 equal to the value of the cell just below it
  
      If comp1 &lt;&gt; comp2 Then 'If the values are different, i.e. we've found the last item in a series of matches
          minimum = Application.WorksheetFunction.Min(Range(Cells(i, 12), Cells(i - rngCount, 12))) 'Find the minimum of the range of cells
          'from Row i in Column D to Row i - rngCount (which is were our series of matches began)
          Cells(i, 14).Value = minimum 'Paste the found minimum in Column N, Row i
          rngCount = 0 'Because the values no longer match, reset our counter
          For j = 1 To lastRowNotional
  
          comp3 = ActiveSheet.Cells(i, 14)
          comp4 = ActiveSheet.Cells(i + 1, 14)
          offset1 = ActiveSheet.Cells(i - 1, 14)
  
              If (comp3 = offset1) And (comp3 &lt;&gt; comp4) Then 'If the selected cell is the last in a block of minima,
          'then we want to replace that cell only with sum of the values in that block
                  Summation = Application.WorksheetFunction.Sum(Range(Cells(i, 12), Cells(i - rngCount, 12)))
              Cells(i, 14).Value = Summation
              End If
      Else 'If the values are the same
          rngCount = rngCount + 1 'increment our range counter until the values do not match
      End If
  Next i
  </code></pre>