Help with copying data to another worksheet

paulageville

New Member
Joined
Oct 4, 2011
Messages
9
Hi all,

I have a macro which I want to search through a list of dates in a range, and for each date found where the given criteria is met, paste the column header into another sheet in the same workbook.
Here is my code...

<code>
Sub compile()


Application.ScreenUpdating = False
Sheets("Matrix").Activate
For Each Cell In Range("d6", "x92")
If Cell.Value = "" Then
ElseIf Cell.Value < Date - 365 Then
Cells(2, Cell.Column).Copy
Sheets("Overdue").Range("a3").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlValues <<<<<<<<<<<<<<<< error
Else
End If
Next


End Sub

</code>

I keep getting a runtime error 1004 when i run it on the highlighted line.

Any ideas? This is driving me nuts!!

Thanks in advance

P
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi. Try this:

Code:
Sub compile2()
  Dim cell As Range, LR As Long
  LR = Sheets("Overdue").Cells(Rows.Count, 1).End(xlUp).Row
  If LR < 3 Then LR = 3
    With Sheets("Matrix")
      For Each cell In .Range("d6", "x92")
        If cell.Value <> "" And cell.Value < Date - 365 Then
          Sheets("Overdue").Cells(LR + 1, 1).Value = cell.Value
          LR = LR + 1
        End If
      Next
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,971
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top