title: Excel 2007 macro to copy paste values based cell value
body: <p>I need to write a macro that compares the date in B1 with the date in columns D1.DB1.  If they match, the column that matches needs to be copied and paste values. This is what I have done so far.  But it is not working.</p>
  
  <pre><code>Sub MyCopyPasteValues()
  ' CopyPasteValus Macro
  ' Macro to hard code last weeks data.
  
  Dim i As Integer
  
  Sheets("data").Range("B1").Select
  
  For i = 4 To 56
  
  If Worksheets("Data").Cells(1, i).Value = "B1" Then
  Range(1, i).Select
  ActiveCell.EntireColumn.Select
  Selection.Copy
  ActiveSheet.PasteSpecial xlPasteValues
  
  End If
  Next i
  
  End Sub
  </code></pre>