VBA PasteAll Question

nrie5

New Member
Joined
Aug 22, 2019
Messages
4
I'm trying to adjust a macro that was using .Select & Pasting pictures, but was throwing a fair amount of Run-time '1004' errors when trying to execute with an RPA tool. I know it's not the cleanest/most efficient, but I'm currently more concerned with the inconsistent results I'm getting. Some companies are correctly populating all the data in every cell, others have #REF ! in all, and some have #REF ! in only some cells. I'm not sure how to correct this.

Sample below - The first part of the code filters a pivot table from one workbook, pastes it to another after clearing existing data. The second part grabs data from the same workbook and pastes the data to another sheet. I need to maintain the formatting so xlPasteValues is not an option even though it fixes the #REF ! issues.

Code:
Windows("CB2.xlsx").Activate


ActiveWorkbook.SlicerCaches("Slicer_Property").ClearManualFilter
For Each Sl_I In ActiveWorkbook.SlicerCaches("Slicer_Property").SlicerItems
' Add "Not" after "If" below if you do not want the indicated item to appear
If Not Sl_I.Value Like "xxxx*" Then Sl_I.Selected = False
Next


'Clear Existing Data
Workbooks("CB.xlsm").Worksheets("xxxx").Cells.ClearContents
'Copy and PasteSpecial between workbooks
Workbooks("CB2.xlsx").Worksheets("Sheet1").Range("A3:E500").Copy
Workbooks("CB.xlsm").Worksheets("xxxx").Range("A35").PasteSpecial Paste:=xlPasteAll


'Paste in the target destination
Workbooks("CB.xlsm").Worksheets("ClosingBell").Range("A333:H362").Copy
Workbooks("CB.xlsm").Worksheets("xxxx").Range("A1").PasteSpecial Paste:=xlPasteAll
'Activate the destination worksheet
Workbooks("CB.xlsm").Worksheets("xxxx").Activate
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
What happens if you paste the values and formats separately? i.e.


Code:
 Workbooks("CB2.xlsx").Worksheets("Sheet1").Range("A3:E500").Copy
    With Workbooks("CB.xlsm").Worksheets("xxxx").Range("A35")
        .PasteSpecial xlValues
        .PasteSpecial xlFormats
    End With
 
Upvote 0
I'm getting a '1004' can't paste here as because the Copy area and paste area aren't the same size. Even after changing a couple of the paste areas to test I'm getting - '1004' To do this, all the merged cells need to be the same size.
 
Upvote 0
Upvote 0
I removed all the merged cells and reconfigured all the ranges. However, the last row or two of everything after the first two slicers is only pasting the values, not the format. The headers aren't bold & aligned right, and the percentages are displaying as decimals.

Code:
Windows("CB2.xlsx").Activate


ActiveWorkbook.SlicerCaches("Slicer_Property").ClearManualFilter
For Each Sl_I In ActiveWorkbook.SlicerCaches("Slicer_Property").SlicerItems
' Add "Not" after "If" below if you do not want the indicated item to appear
If Not Sl_I.Value Like "xxxx*" Then Sl_I.Selected = False
Next


'Clear Existing Data
Workbooks("CB.xlsm").Worksheets("xxxx").Cells.ClearContents
'Copy and PasteSpecial between workbooks
Workbooks("CB2.xlsx").Worksheets("Sheet1").Range("A3:E500").Copy
Workbooks("CB.xlsm").Worksheets("xxxx").Range("A35").PasteSpecial Paste:=xlPasteAll


'Paste in the target destination
Workbooks("CB.xlsm").Worksheets("CB").Range("A59:H86").Copy
    With Workbooks("CB.xlsm").Worksheets("xxxx").Range("A1:H27")
            .PasteSpecial xlValues
            .PasteSpecial xlFormats
    End With
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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