Pivottable VBA code error while running macros in excel 2010

rshanka2

New Member
Joined
May 10, 2016
Messages
2
Please help. I am currently merging a pivot table from one workbook to other. Once I merge and run macro, its giving pivot table errors such as User defined, run time 1004 and unable to get pivot table property of class sheet, Any help is appreciated. I want to be able to run pivot table macro on any worksheet. I don't come from a VBA background. What code should I write?...Please help. Thanks Everyone

Sub Rollup()
'
' Rollup Macro
'

'

Dim LR As Long
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Dim pt As PivotTable
ActiveWorkbook.Sheets("Enterprise Lane Roll Up").Select.................ERROR MESSAGE
Set objTable = Sheet1.PivotTableWizard

Sheets("Enterprise Lane Roll Up").Selec
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Sheets("Enterprise Lane Roll Up").Select
ActiveSheet.PivotTables("PivotTable5").PivotCache.Refresh
Columns("A:I").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("J2").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range("J2:J" & LR), Type:=xlFillDefault
Range("J2:J" & LR).Select
Columns("J:J").Select
Range("J397").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("K1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Lane ID"
Cells.Select
ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort.SortFields.Add Key _
:=Range("J2:J" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort
.SetRange Range("A1:K" & LR)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("K2").Select
ActiveCell.FormulaR1C1 = "1"
Range("K3").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=R[-1]C[-1],R[-1]C,R[-1]C+1)"
Selection.AutoFill Destination:=Range("K3:K" & LR), Type:=xlFillDefault
Range("K3:K" & LR).Select
Columns("K:K").Select
Range("K397").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("L1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "O"
Cells.Select
ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort.SortFields.Add Key _
:=Range("K2:K" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort.SortFields.Add Key _
:=Range("L2:L" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort
.SetRange Range("A1:L" & LR)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("L2").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(RC[-1]=R[-1]C[-1],RC[-7]=R[-1]C[-7]),"""",RC[-7])"
Selection.AutoFill Destination:=Range("L2:L" & LR), Type:=xlFillDefault
Range("L2:L" & LR).Select
ActiveWindow.SmallScroll Down:=-66
Columns("L:L").Select
Range("L331").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("M1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "O St Merge"
Range("M1").Select
ActiveWindow.SmallScroll Down:=-15
Cells.Select
ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Enterprise Lane Roll Up").Sort.SortFields.Add Key _
:=Range("K2:K" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
 

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,328
Messages
6,124,299
Members
449,149
Latest member
mwdbActuary

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