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