Chirag R Raval
Member
Dear Experts,
Subject :- " Why VBA Stuck on just Selection.copy ..Compile Error-"Expected Function Or Variable"
I have Picot Table Code as below...but error on "Selection" "Compile Error"
""Expected Function or Variable " on following line
"ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
selection.Copy
I also uplod & attached my database file on which this code should be run...for your reference....
whole oiginal code is here...
What VBA Want??...Why VBA stuck on just on minor Selection word...?
hope your co-operations & help will always be appreciated..
Regards,
Chirag Raval
Subject :- " Why VBA Stuck on just Selection.copy ..Compile Error-"Expected Function Or Variable"
I have Picot Table Code as below...but error on "Selection" "Compile Error"
""Expected Function or Variable " on following line
"ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
selection.Copy
I also uplod & attached my database file on which this code should be run...for your reference....
whole oiginal code is here...
Code:
Sub Shirting_book_Summary()
Dim PCache As PivotCache
Dim LastRow As Long
Dim pt As PivotTable
'If "Pivot" worksheet already exists, delete it
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Pivot").Delete
On Error GoTo 0
Application.DisplayAlerts = True
Worksheets("Sheet1").Activate
Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=1, SourceData:=range("A1").CurrentRegion.Address)
Worksheets.add
ActiveSheet.Name = "Pivot"
ActiveWindow.DisplayGridlines = False
Set pt = ActiveSheet.PivotTables.add(PivotCache:=PCache, TableDestination:=range("A1"), TableName:="PivotTable1")
With ActiveSheet.PivotTables("PivotTable1").PivotFields("AR")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("CHNL")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("BUY")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PARTY")
.Orientation = xlRowField
.Position = 4
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("CONF" & Chr(10) & "UNT"), "Sum of CONF" & Chr(10) & "UNT", xlSum
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("CONF" & Chr(10) & "QTY"), "Sum of CONF" & Chr(10) & "QTY", xlSum
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("VALUE"), "Sum of VALUE", xlSum
ActiveSheet.PivotTables("PivotTable1").PivotFields("AR").LayoutForm = xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotFields("CHNL").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotFields("BUY").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable1").PivotFields("BUY").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotFields("PARTY").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable1").PivotFields("PARTY").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
selection.Copy
Sheets.add
ActiveSheet.Name = "Summary"
selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End With
Columns("E:G").Select
Application.CutCopyMode = False
selection.NumberFormat = "##,###"
Cells.Select
Cells.EntireColumn.AutoFit
range("A1").Select
ActiveCell.FormulaR1C1 = "AR"
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Rows("1:1").Select
selection.Replace What:="SUM OF ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
range("E1").Select
ActiveCell.FormulaR1C1 = "CONF" & Chr(10) & "UNT"
range("F1").Select
ActiveCell.FormulaR1C1 = "CONF" & Chr(10) & "QTY"
range("G1").Select
ActiveCell.FormulaR1C1 = "VALUE"
Rows("2:2").EntireRow.Delete
Cells.Select
Cells.EntireColumn.AutoFit
Columns("A:G").Select
With selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("D:D").Select
With selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Columns("E:G").Select
With selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlCenter
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
range("A1").Activate
range(ActiveCell, ActiveCell.CurrentRegion.SpecialCells(xlCellTypeLastCell)).Select
selection.Borders(xlDiagonalDown).LineStyle = xlNone
selection.Borders(xlDiagonalUp).LineStyle = xlNone
With selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Cells.Select
With selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
range("A1").Select
' Sheets("Sheet1").Select
' ActiveWindow.SelectedSheets.Delete
End With
End Sub
What VBA Want??...Why VBA stuck on just on minor Selection word...?
hope your co-operations & help will always be appreciated..
Regards,
Chirag Raval