title: how do I have a macro operate on a range of cells that I selected beforehand?
body: <p>So, I have a macro that loops through a lot of cells on the worksheet and does stuff to them. </p>
  
  <p>Here's the code <a href="http://pastie.org/4290581" rel="nofollow">http://pastie.org/4290581</a></p>
  
  <pre><code>Private Sub ReplaceFormulaWithValues()
      Dim lastrow As Long, r1 As Long
      Dim temp As String, arTemp
      Dim temp2 As String
      Dim temp3 As String
  
      Dim letter
  
      temp3 = ""
  
          ' Get the last row in the worksheet
      lastrow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
  
      For r1 = 1 To lastrow
  
          For r2 = 0 To 10
              letter = Chr(Asc("A") + r2)
              letter = letter + LTrim(Str(r1))
  
  
              ' If A &amp; B aren't blank, make the formula of cell C equal to A + B.
              If Sheet1.Range(letter).Value &lt;&gt; "" And Mid(Sheet1.Range(letter).Formula, 1, 1) = "=" Then
                  If Asc(Mid(Sheet1.Range(letter).Formula, 2, 1)) &gt;= 65 And Asc(Mid(Sheet1.Range(letter).Formula, 2, 1)) &lt;= 90 Then
                      ' Get the formula for the current C cell
                      temp = Replace(Sheet1.Range(letter).Formula, "=", "")
  
                      'Create an array by splitting the formula on the + sign
                      arTemp = Split(temp, "+")
  
                      temp2 = Sheet1.Range(arTemp(0)).Value
  
                      For i = 1 To UBound(arTemp)
                          temp3 = Sheet1.Range(arTemp(i)).Value
                          temp2 = temp2 &amp; "+" &amp; temp3
  
                      Next i
  
                      Sheet1.Range(letter).Value = "=" &amp; temp2
                  End If
  
              End If
  
          Next
      Next
  End Sub
  </code></pre>
  
  <p><a href="http://www.reddit.com/r/excel/comments/wvd02/question_replace_the_cell_reference_in_the/" rel="nofollow">This</a> is what it does:</p>
  
  <pre><code>for instance, let's say that the formula of cell C2 is C2=A1+B1, where A1 = 10 and B1 = 20.
  I would like to change it so that the formula of cell C2 is C2=10+20.
  However, I don't want the formula displayed in the cell or anything.
  </code></pre>
  
  <p>My question: how do I set it up so that I first can highlight/select a group of cells from the worksheet, THEN activate the macro so that the macro only works on every cell in that range?</p>