[Error1004] Copying a range to destination due to PivotTable

ITookUrJob

New Member
Joined
Oct 13, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I get the error stating that I can't make this change (or copy a range to a destination) because it will affect Pivot Table.

Now there are two solutions I thought of:

• Deleting Pivot Tables entirely. But this is pointless as my report requires it.
• Referencing table in targetWb.Sheets(n).Range("A2"). How would you copy a range to a destination that is a listobject in position cell A2?

Essentially, I am trying to import workbook from range to a table that is connected to a PivotTable.

VBA Code:
Sub FillWithPastedVal_2() 'make this run twice for ECC and SRM

Dim i As Long, j As Long, n As Integer
Dim targetWb As Workbook
Dim f As String
Dim SheetN(1 To 2) As String
Dim SourceRng As Range

'Populate the array
SheetN(1) = "ECC Extract"
SheetN(2) = "SRM Extract"

Set targetWb = Workbooks("Outline Agreement Tool_m.xlsx")

For n = 1 To 2

    MsgBox "Workbook" & "(" & n & ")" & " for " & SheetN(n), vbInformation
    
    
    f = Application.GetOpenFilename(filefilter:="Excel Files,*.xl*;*.xm*")
        
    Set sourceWb = Workbooks.Open(f)
    
    With sourceWb.ActiveSheet
        i = .Cells(Rows.Count, 1).End(xlUp).Row
        j = .Cells(2, Columns.Count).End(xlToLeft).Column
    End With
    
    MsgBox sourceWb.Name & targetWb.Name
    
    Debug.Print "R" & i & " C" & j
    
    Set SourceRng = sourceWb.ActiveSheet.Range(Cells(2, 1), Cells(i, j))

'This should be OUTLINE AGREEMENT TOOL

    SourceRng.Copy targetWb.Sheets(n).Range("A2")
    

Next n
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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