+ Reply to Thread
Results 1 to 2 of 2

[Err1004] Copy error due to PivotTable or Table

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-20-2021
    Location
    UK
    MS-Off Ver
    2016
    Posts
    126

    [Err1004] Copy error due to PivotTable or Table

    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.

    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

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,750

    Re: [Err1004] Copy error due to PivotTable or Table

    Please attach the actual file so we can see where everything is. (See yellow banner at the top of the page.)
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PivotTable VBA Error
    By BILLONEILL40 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2019, 12:38 PM
  2. Copy/Match Table Filter to PivotTable
    By chrisgoud in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2018, 05:50 PM
  3. Replies: 0
    Last Post: 01-05-2017, 09:55 AM
  4. Error PivotTable External Data Source With Linked Table
    By goss in forum Excel Charting & Pivots
    Replies: 11
    Last Post: 05-29-2014, 11:38 PM
  5. Replies: 1
    Last Post: 09-11-2013, 02:27 PM
  6. Error with PivotTable?
    By ItsTehShadow in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-10-2013, 06:18 AM
  7. [SOLVED] Pivottable Error
    By mmwheeler in forum Excel General
    Replies: 0
    Last Post: 07-28-2005, 09:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1