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.
Bookmarks