+ Reply to Thread
Results 1 to 2 of 2

VBA Adding In Pivot Table Instead of Shifting Column Over

  1. #1
    Registered User
    Join Date
    07-15-2015
    Location
    Nowhere
    MS-Off Ver
    2007
    Posts
    2

    VBA Adding In Pivot Table Instead of Shifting Column Over

    Hi all.

    I've been recently having some issues with a VBA code I've been using that involves copying a Pivot Table (but not the Pivot Table itself) over to another sheet.

    The next step of the VBA code involves shifting column A over

    Sheets("Pivot").Select
    Range("A1").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    Columns("A:B").Select
    Selection.Copy
    Sheets("Pivot2").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "Match"
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[1]=""(blank)"",1,0)"
    Range("A2").Select
    Selection.AutoFill Destination:=Range("A2:A" & Range("B" & Rows.Count).End(xlUp).Row)

    Fairly straight forward right? But when it gets to this line of code, everything starts going heywire.

    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

    Instead of shifting column A over, it inserts the previously copied Pivot Table (not just the raw figures), shifting the data I want to manipulate from columns B and C to columns C and D with an unwanted Pivot Table in columns A and B.

    I've been working with this particular VBA for two years and I have never had this problem until today, so I don't think it is the code itself, especially since it was working fine this morning when I was using it on another machine and have made no changes to the code since April.

    I think lies with something in Excel. I notice now that whenever I copy something and then right click on a cell/column, the "Insert Copied Cells" selection always comes up as a first choice before the regular "Insert Cells" selection.

    Whether or not this has anything to do with the actual problem I am not sure, but I am trying to avoid completely rewritting a Macro code I wrote two years ago. The version of Excel I am using is Excel 2016. It seems to work find on Excel 2010 or at least it was as of this morning.

    Any and all help will be appreciated.

    Thank you.

    EDIT: Tried disabling "Insert Copied Cells" option on context menu. Was able to do it, but didn't solve the issue.
    Last edited by pmoehrin; 06-19-2017 at 09:21 PM.

  2. #2
    Registered User
    Join Date
    07-15-2015
    Location
    Nowhere
    MS-Off Ver
    2007
    Posts
    2

    Re: VBA Adding In Pivot Table Instead of Shifting Column Over

    Entered in the "Clear Clipboard" code line before the column shift and it seems to have solved it.

    Application.CutCopyMode=False

    But the why the issue suddenly came up through remains.

+ 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. Adding Column to Pivot Table
    By hthoma11 in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 08-25-2016, 12:08 PM
  2. Adding numbers in shifting column
    By JHC in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2015, 03:31 AM
  3. Adding a formula column based on the pivot table's Grand Total column
    By trisoldee in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-26-2014, 05:29 PM
  4. Adding blank column to Pivot Table
    By GPSPOW in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 12-09-2014, 04:06 PM
  5. Pivot table- adding a column
    By bojker in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 09-21-2012, 04:33 PM
  6. Replies: 0
    Last Post: 08-14-2012, 09:42 AM
  7. Adding a column to a pivot table
    By ezzy85 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2008, 03:01 AM

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