PasteSpecial method of Range class failed

Dobin1s

New Member
Joined
May 18, 2016
Messages
8
Hi im trying to run a bit of code thats always worked fine before and has not been recently changed however now im getting this error "PasteSpecial method of Range class failed" when getting to the line in red below

Selection.EntireRow.Hidden = False 'unhidden
Range("A" & MOVEROW).EntireRow.Select 'select whole row to move
Range("A" & MOVEROW).EntireRow.Copy 'copy whole row to move
Sheets(3).Select
If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData 'show all
Range("A65536").End(xlUp).Offset(1, 0).Select 'goes to bottom of spreadsheet and then shift end up
If ActiveCell.Row = 2 Then Selection.Offset(1, 0).Select 'stop info going in row 2
TOLINE = ActiveCell.Row 'defines line pasting info to
Range("A" & TOLINE).Select 'selects bottom row on TO sheet
Selection.PasteSpecial Paste:=xlPasteValues
Selection.PasteSpecial Paste:=xlPasteFormats

Im a little confused because the code hasnt been changed since it was last run so im not sure if there is anything wrong at all...


Thanks in advance
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Welcome to the Board!

Do you have any merged, protected, or hidden cells in column A?
 
Upvote 0
Try this alternate code. I have not created Sample data to test it, so please try it on a COPY of your spreadsheet.

Code:
Sub PSpecial()

Selection.EntireRow.Hidden = False 'unhidden
Range("A" & MOVEROW).EntireRow.Copy 'copy whole row to move

If Sheets(3).FilterMode Then
    Sheets(3).ShowAllData 'show all
End If

Sheets(3).Range("A65536").End(xlUp).Offset(1, 0).Select 'goes to bottom of spreadsheet and then shift end up

If ActiveCell.Row <= 2 Then
    TOLINE = 3
Else
    TOLINE = ActiveCell.Row
End If

Sheets(3).Range("A" & TOLINE).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
 
End Sub

Regards
Caleeco
 
Last edited:
Upvote 0
I tried the below but it still gave me the same error for some reason :(

Try this alternate code. I have not created Sample data to test it, so please try it on a COPY of your spreadsheet.

Code:
Sub PSpecial()

Selection.EntireRow.Hidden = False 'unhidden
Range("A" & MOVEROW).EntireRow.Copy 'copy whole row to move

If Sheets(3).FilterMode Then
    Sheets(3).ShowAllData 'show all
End If

Sheets(3).Range("A65536").End(xlUp).Offset(1, 0).Select 'goes to bottom of spreadsheet and then shift end up

If ActiveCell.Row <= 2 Then
    TOLINE = 3
Else
    TOLINE = ActiveCell.Row
End If

Sheets(3).Range("A" & TOLINE).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
 
End Sub

Regards
Caleeco
 
Upvote 0
Hello,

Does it fail on the same line?

Code:
Sheets(3).Range("A" & TOLINE).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
 
Upvote 0
Try using the F8 to step through the code line-by-line to see what happens.
What is the value of TOLINE just before the error?
 
Upvote 0
No it was failing (well highlighting) on


Sheets(3).Range("A65536").End(xlUp).Offset(1, 0).Select
 
Last edited by a moderator:
Upvote 0
Ive tried stepping through and im none the wiser :( (im quite new to this and only self taught really)

The value of TOLINE is a row on another tab where i want the info pasted to...when i hover over it as its running it is showing the correct row number
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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