Reddog94

Board Regular
Joined
Dec 20, 2011
Messages
52
The code below works fine to open another workbook, copy data, then paste into the original file. However, I need to paste only values. I have tried a couple different ways of doing it after the fact (ie after pasting data formulas and all), but nothing has worked and I would prefer to just paste values initially.

Can anyone tell me how to alter the code below to only paste values?

Code:
On Error GoTo ErrorHandler
Application.Workbooks.Open Filename:=Range("FILEPATH"), Password:=("yobaby3")
Dim rCopy As Range
Dim rPaste As Range
    Set rCopy = Range("RANGE_DETAIL")
    
Application.Workbooks("Rebuild 11").Activate
    Set rPaste = Range("Detail_Paste_Range")
    
    rPaste.Clear
      
    rCopy.Copy rPaste
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
It works - thank you thank you!

Would you be willing to explain something to me? Before I posted this issue on the board, I tried a similar code except all on one line:

Code:
rCopy.Copy rPaste.PasteSpecial Paste:=xlPasteValues

How come I got an error when it was on one line but putting it on two like you suggested worked? I'm new to vb so don't know some of the nuances yet - why does having it on another line matter?
 
Upvote 0
How come I got an error when it was on one line but putting it on two like you suggested worked? I'm new to vb so don't know some of the nuances yet - why does having it on another line matter?

That's just one of those quirks. You can do a direct copy/paste on one line, but to apply any paste special formats you need to extend it to a second line.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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