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...
PS. rdata, control and data refer to worksheets defined earlier in the code..
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: