Trying to paste values only without Select/Copy

StuLux

Well-known Member
Joined
Sep 14, 2005
Messages
682
Office Version
  1. 365
Platform
  1. Windows
Hi folks, long time since I came to this board for help and many thanks to all those who have helped me in past years. I'm trying to improve my code so that instead of actually selecting a range and then pasting as values I am trying to use the following code

Code:
        Sheet1.Range("B2:F" & RecordCount).Cells.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets(SheetName).Range("B" & RowNumber).Value

I believe the .Value at the end should ensure it only pastes values and not formatting etc. but when I add the .Value to my code I get "Copy Method of Range Class Failed". The code works without the .Value but pastes formulas and formatting instead of just values. What am I doing wrong?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this:

Code:
  Sheet1.Range("B2:F" & RecordCount).Cells.SpecialCells(xlCellTypeVisible).Copy
  Sheets(SheetName).Range("B" & RowNumber).PasteSpecial Paste:=xlPasteValues
  Application.CutCopyMode = False
 
Upvote 0
You could remove the destination from that line and use a paste special line instead:

Code:
Sheets(SheetName).Range("B" & RowNumber).PasteSpecial xlPasteValues
 
Upvote 0
Thanks for the suggestion the code is now working by separating the destination to a separate line as follows:

Code:
        Sheet1.Range("B2:F" & RecordCount).Cells.SpecialCells(xlCellTypeVisible).Copy        
Sheets(SheetName).Range("B" & RowNumber).PasteSpecial Paste:=xlPasteValues
 
Last edited:
Upvote 0
Thanks for the suggestion the code is now working by separating the destination to a separate line as follows:
Code:
 Sheet1.Range("B2:F" & RecordCount).Cells.SpecialCells(xlCellTypeVisible).Copy 
       Sheets(SheetName).Range("B" & RowNumber).PasteSpecial Paste:=xlPasteValues
 
Last edited:
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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