Copy, paste, delete row

R0d

New Member
Joined
Jan 14, 2007
Messages
44
Hi everyone

I am looking for a macro that will look through columns X, AA & AC which contain dates on sheet1. If any of the dates are more than 30 days old, copy the row and paste it into sheet2 under the last entry. Finally delete the row copied in sheet1.

Thanks in advance
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Where does your data begin and end in Sheet1? Are you copying from column A to column AC? Or does it extend further? Do you have a header row on sheet1?
 
Upvote 0
Hi Irobbo314

The data for the columns X,AA & AC begins on row 5 and I would anticipate it would not extend any further than row 250. I would like to copy from column A to column AE. There are no header rows.
 
Upvote 0
Try the following code.

Code:
Sub copyover()
On Error GoTo ERH
Dim ws1 As Worksheet: Set ws1 = Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = Sheets("Sheet2")
Dim AR() As Variant: AR = ws1.Range("A5:AE" & ws1.Range("A" & Rows.Count).End(xlUp).Row).Value
Dim LR As Long

For i = UBound(AR) To LBound(AR) Step -1
    If Now() - AR(i, 24) > 30 Or Now() - AR(i, 27) > 30 Or Now() - AR(i, 29) > 30 Then
        ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(1, 29).Value = Application.Index(AR, i, 0, 1)
        ws1.Rows(i).EntireRow.Delete
skip:
    End If
Next i

Exit Sub

ERH:

If Err.Number = 13 Then
    Resume skip
Else
    MsgBox "Error: " & Err.Description, vbCritical, "Error"
End If

End Sub
 
Upvote 0
Just tried your code, but it is taking out the first 4 rows on sheet1. These rows need to stay.
 
Upvote 0
So rows 5-8 are being deleted? If so, what dates are in columns X, AA, and AC in those rows?
 
Upvote 0
Hi Irobbo314

I think I have some corrupt data in the workbook somewhere, the other macros I have in the workbook are not running how they should either. Will resolve this issue and have another go at it later.

Thanks for your time.
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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