Problems with Copy and pasting. Works with one but not the other

keeegs

Board Regular
Joined
Sep 25, 2011
Messages
145
Hi Guys

I'm having some troubles with my macros.
Basically it goes through and checks how old certain records are and if they are over a certain age it moves it to a archive file (to keep the working file small and running fast)

Code:
Sub INVCheck()
'Spec Archieve Checks
For Each CL In Workbooks(INV).Sheets("Specs Archive").Range("A4:A" & Workbooks(INV).Sheets("Specs Archive").Range("a65536").End(xlUp).Row)
If DateDiff("m", CL.Offset(0, 10), Date) > 3 Then
If Not SAR = vbNullString Then
SAR = SAR & ","
End If
SAR = SAR & CL.Row & ":" & CL.Row
End If
Next CL
'Register Checks
For Each CL In Workbooks(INV).Sheets("Register").Range("A4:A" & Workbooks(INV).Sheets("Register").Range("a65536").End(xlUp).Row)
If DateDiff("d", CL.Offset(0, 10), Date) > 12 Then
    If CL.Offset(0, 35) = vbNullString Then
        If Not RAR = vbNullString Then
        RAR = RAR & ","
        End If
    RAR = RAR & CL.Row & ":" & CL.Row
    Else
    If DateDiff("d", CL.Offset(0, 37), Date) > 12 And CL.Offset(0, 39) = vbNullString Then
        If Not RAR = vbNullString Then
        RAR = RAR & ","
        End If
    RAR = RAR & CL.Row & ":" & CL.Row
    Else
    If Not CL.Offset(0, 39) = vbNullString And DateDiff("d", CL.Offset(0, 41), Date) > 12 Then
        If Not RAR = vbNullString Then
        RAR = RAR & ","
        End If
    RAR = RAR & CL.Row & ":" & CL.Row
    End If
    End If
    End If
End If
Next CL
End Sub

This is the code that checks the records to see how old they are. it works fine. not a problem

Code:
Sub Cleanup()
Application.ScreenUpdating = False
Application.Calculation = xlManual
If Workbooks(INV).ReadOnly = True Then
MsgBox "Cannot run the Clean up when " & INV & " is Read Only"
Exit Sub
End If
Workbooks.Open (MyPath & AF)
If Workbooks(AF).ReadOnly = True Then
MsgBox "Cannot run the Clean up when " & AF & " is Read Only"
Windows(AF).Close
Exit Sub
End If
 
 
Call INVCheck
If Not RAR = vbNullString Then
Workbooks(INV).Activate
Sheets("Register").Select
Range(RAR).Select
Selection.Copy
Workbooks(AF).Activate
Sheets("Releases").Select
Range("a65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Workbooks(INV).Activate
Range(RAR).Select
Selection.Delete
Range("A1").Select
Else
MsgBox "No RAR"
End If
 
 
Call INVCheck
If Not SAR = vbNullString Then
Workbooks(INV).Activate
Sheets("Specs Archive").Select
Range(SAR).Select
Selection.Copy
Workbooks(AF).Activate
Sheets("Specss").Select
Range("a65536").End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
Workbooks(INV).Activate
Range(SAR).Select
Selection.Delete
Range("A1").Select
Else
MsgBox "No SAR"
End If
Windows(AF).Close True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub


this is the code that will copy and paste the data to the archieve.
First section checks that both workbooks are readwrite
Then the second section will move the range RAR. That works.

Then the third section is the code that I have problems with it.
It is the same as the 2nd section but it always cause an error with this section of code.
Code:
Selection.Copy


any ideas as to why it doesnt want to copy?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,203,674
Messages
6,056,680
Members
444,881
Latest member
Stu2407

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