paste special with formatting and without formula

Dave_george

New Member
Joined
Jul 20, 2023
Messages
32
Office Version
  1. 2021
  2. 2016
  3. 2013
Platform
  1. Windows
Hello,

I have a Macro below that let's me grab data from other workbook. I need it to copy data without formula but needs to include the formatting.


Sub Copy_from_workbook()

Workbooks.Open "C:\Users\grg01\Desktop\perf.xlsx"

Workbooks("perf").Worksheets("Sheet4").Range("A1:F6").Copy _
Workbooks("dest").Worksheets("Figures").Range("B5:G10")

Workbooks("perf").Close SaveChanges:=True

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Maybe:
VBA Code:
Sub Copy_from_workbook()
    Dim wbPerf As Workbook, wbThis As Workbook
    
    Set wbPerf = Workbooks.Open("C:\Users\grg01\Desktop\perf.xlsx")
    Set wbThis = ThisWorkbook
    
    wbPerf.Worksheets("Sheet4").Range("A1:F6").Copy
    With wbThis.Sheets("Figures").Range("B5:G10")
        .PasteSpecial xlPasteValues
        .PasteSpecial xlPasteFormats
    End With
    
    Application.CutCopyMode = False
    wbPerf.Close True
End Sub
 
Upvote 1
Solution
Maybe:
VBA Code:
Sub Copy_from_workbook()
    Dim wbPerf As Workbook, wbThis As Workbook
   
    Set wbPerf = Workbooks.Open("C:\Users\grg01\Desktop\perf.xlsx")
    Set wbThis = ThisWorkbook
   
    wbPerf.Worksheets("Sheet4").Range("A1:F6").Copy
    With wbThis.Sheets("Figures").Range("B5:G10")
        .PasteSpecial xlPasteValues
        .PasteSpecial xlPasteFormats
    End With
   
    Application.CutCopyMode = False
    wbPerf.Close True
End Sub
Got a run time error on line .PasteSpecial xlPasteValues
 
Upvote 0
Got a run time error on line .PasteSpecial xlPasteValues
1693913015984.png
 
Upvote 0
It sounds like you are using merged cells.
If at all possible, GET RID OF THEM!

Merged cells are one of the absolute worst features of Excel, and cause all sorts of issues for things like VBA and sorting.
As such, most experienced programmers will avoid them like the plague!

If you are just merging columns across single rows, it is much better to use the "Center Across Selection" formatting feature, which gives you all the same visual benefits of merged cells without all the issues.
See: Tom’s Tutorials For Excel: Using Center Across Selection Instead of Merging Cells – Tom Urtis
 
Upvote 1
It sounds like you are using merged cells.
If at all possible, GET RID OF THEM!

Merged cells are one of the absolute worst features of Excel, and cause all sorts of issues for things like VBA and sorting.
As such, most experienced programmers will avoid them like the plague!

If you are just merging columns across single rows, it is much better to use the "Center Across Selection" formatting feature, which gives you all the same visual benefits of merged cells without all the issues.
See: Tom’s Tutorials For Excel: Using Center Across Selection Instead of Merging Cells – Tom Urtis
Thanks a bunch. Got rid of the cells and it worked like a charm. Also learnt something new.
 
Upvote 0
Maybe:
VBA Code:
Sub Copy_from_workbook()
    Dim wbPerf As Workbook, wbThis As Workbook
   
    Set wbPerf = Workbooks.Open("C:\Users\grg01\Desktop\perf.xlsx")
    Set wbThis = ThisWorkbook
   
    wbPerf.Worksheets("Sheet4").Range("A1:F6").Copy
    With wbThis.Sheets("Figures").Range("B5:G10")
        .PasteSpecial xlPasteValues
        .PasteSpecial xlPasteFormats
    End With
   
    Application.CutCopyMode = False
    wbPerf.Close True
End Sub
Thank you. It worked after removing merged cells from my workbook.
 
Upvote 0
Happy we could help, glad you got it sorted. I also agree with what was said about merged cells, they are a huge pain.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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