Cut and Paste Filtered Range

bastinoboy

New Member
Joined
Sep 6, 2012
Messages
1
Hi,
I am new to this forum and a (relatively) new user to VBA. I am currently trying to implement a macro that, amongst other things, filters a table on one worksheet then copies the result to another in the same workbook. I had this working fine. Now, for some reason it does not work and I recieve the following runtime error:

'PasteSpecial method of Range class failed'

The code I use is posted below. Any help with this issue would be massively appreciated, as it has had me pulling my hair out for days trying to find the problem...

Code:
With control
        
        rdata.Range("A:AY").clear
        
        With data
            .AutoFilterMode = False
            .Range("A1:AY1").AutoFilter
            .Range("A1:AY1").AutoFilter Field:=4, Criteria1:=">=" & d1, Operator:=xlAnd, Criteria2:="<=" & d2
            Set filt = Selection.CurrentRegion.SpecialCells(xlCellTypeVisible)
            filt.Copy
        End With
        
        rdata.Activate
        rdata.Cells(2, 1).Activate
        
        With rdata
            Selection.PasteSpecial xlPasteValuesAndNumberFormats
            .Range("A2:AY2").EntireColumn.AutoFit
        End With
        
        control.Range("A1:AY1").CurrentRegion.AutoFilter
        control.Activate
    
End With

PS. rdata, control and data refer to worksheets defined earlier in the code..
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,630
Messages
6,173,453
Members
452,514
Latest member
cjkelly15

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