Copy Paste Macro Edit

Alex O

Active Member
Joined
Mar 16, 2009
Messages
345
Office Version
  1. 365
Platform
  1. Windows
I thought this would paste values only, but for some reason it's pasting my formulas. How can this macro be edited to copy and paste values?

Thanks

Sub NewUploadFile()
Dim wb As Workbook
Set wb = Workbooks.Add

'copy and paste
ThisWorkbook.Worksheets(1).Range("B1:P2000").Copy _
Destination:=wb.Sheets("Sheet1").Range("A1")

wb.Sheets("Sheet1").Columns.AutoFit

Set wb = Nothing
 

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

Code:
Sub NewUploadFile()
Dim wb As Workbook
Set wb = Workbooks.Add

'copy and paste
ThisWorkbook.Worksheets(1).Range("B1:P2000").Copy
wb.Sheets("Sheet1").Range("A1").PasteSpecial Paste:=xlPasteValues

wb.Sheets("Sheet1").Columns.AutoFit

Set wb = Nothing
 
Upvote 0
ThisWorkbook.Worksheets(1).Range("B1:P2000").Copy
wb.Sheets("Sheet1").Range("A1").PasteSpecial xlValues
 
Upvote 0
VoG
Your're solution works great, but I loose my formatting (borders, shading, etc.) any way to preserve that as well?

Thanks
 
Upvote 0
Try

Code:
Sub NewUploadFile()
Dim wb As Workbook
Set wb = Workbooks.Add

'copy and paste
ThisWorkbook.Worksheets(1).Range("B1:P2000").Copy
With wb.Sheets("Sheet1")
    .Range("A1").PasteSpecial Paste:=xlPasteValues
    .Range("A1").PasteSpecial Paste:=xlPastenumberformats
    .Range("A1").PasteSpecial Paste:=xlPasteFormats
    .Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
End With
Set wb = Nothing
 
Upvote 0
Or
Code:
ThisWorkbook.Worksheets(1).Range("B1:P2000").Copy wb.Sheets("Sheet1").Range("A1")
 
With wb.Sheets("Sheet1").Range("A1:O2000")
.Formula=.Value
End With
 
Upvote 0
I'm getting Run-time error "1004": PasteSpecial method of range class failed message.

.Range("A1").PasteSpecial Paste:=xlPastenumberformats

Got the same result with njimack's suggestion....
 
Upvote 0
Try

Code:
Sub NewUploadFile()
Dim wb As Workbook
Set wb = Workbooks.Add

'copy and paste
ThisWorkbook.Worksheets(1).Range("B1:P2000").Copy
With wb.Sheets("Sheet1")
    .Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    .Range("A1").PasteSpecial Paste:=xlPasteFormats
    .Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
End With
Set wb = Nothing
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,703
Members
452,938
Latest member
babeneker

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