数据透视缓存语法出错

时间:2017-03-04 18:53:46

标签: vba excel-vba excel

运行以下代码"输入不匹配"宏到达此行时出现错误:

    case MotionEvent.ACTION_UP: {

    LayoutInflater lifirst = LayoutInflater.from(MainActivity.this);
    View lifirstpv = lifirst.inflate(R.layout.infirst, null);
    final TextView editfirst = TextView)lifirstpv.findViewById(R.id.editfirst);
    final TextView deletefirst = (TextView)lifirstpv.findViewById(R.id.deletefirst);

    pop = new PopupWindow(
lifirstpv,RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);

    pop.setOutsideTouchable(true); pop.setTouchable(true);
    deletefirst.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    rel0.removeView(teext);
    pop.dismiss();
    return true;
                   }
          });

如何更正代码错误?

Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PRange).CreatePivotTable(TableDestination:=PSheet.Cells(2, 2), TableName:="ERA_Dashboard")

1 个答案:

答案 0 :(得分:0)

无需删除和重新创建"摘要"表,只需使用下面的代码。下面的代码将在"摘要"中创建(或更新) def main(): squareFeet = float(input("Enter square feet of wall space to be painted: ")) pricePerGallon = float(input("Enter price of gallon of paint: ")) gallonsRequired = calcGallons hoursRequired = calcHours paintCost = calcPaintCost laborCost = calcLabor totalCost = calcTotal def calcGallons() : gallonsRequired = (squareFeet / 115) return gallonsRequired def calcHours() : hoursRequired = (squareFeet / 115) * 8 return hoursRequired def calcPaintCost() : paintCost = pricePerGallon * gallonsRequired return paintCost def calcLabor() : laborCost = hoursRequired * 40 return laborCost def calcTotal() : totalCost = laborCost + paintCost return totalCost print(" Gallons of paint required: ", gallonsRequired) print(" Hours of labor required: ", hoursRequired) print("Cost of paint: ", paintCost) print("Cost of labor: ", laborCost) print("Total cost of paint job: ", totalCost) main() 数据透视表。已更新PTable

的工作表

代码

PCache

修改1

Option Explicit

Sub Pivot()

Dim PSheet As Worksheet
Dim DSheet As Worksheet
Dim PCache As PivotCache
Dim PTable As PivotTable
Dim PRange As Range
Dim LastRow As Long
Dim LastCol As Long

Set PSheet = Worksheets("Summary")
Set DSheet = Worksheets("Content")

With DSheet
    LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
    Set PRange = .Range("A1").Resize(LastRow, LastCol) ' set data range for Pivot Table
End With

'Set the Pivot Cache
Set PCache = ActiveWorkbook.PivotCaches.Add(xlDatabase, PRange)

' add this line in case the Pivot table doesn't exit >> first time running this Macro
On Error Resume Next
Set PTable = PSheet.PivotTables("ERA_Dashboard") ' check if "ERA_Dashboard" Pivot Table already created (in past runs of this Macro)

On Error GoTo 0
If PTable Is Nothing Then

    ' create a new Pivot Table in "Summary" sheet
    Set PTable = PSheet.PivotTables.Add(PivotCache:=PCache, TableDestination:=PSheet.Range("A1"), TableName:="ERA_Dashboard")

    With PTable.PivotFields("Issue Status")
        .Orientation = xlRowField
        .Position = 1
    End With
    With PTable.PivotFields("Issue Status")
        .Orientation = xlDataField
        .Position = 1
        .Function = xlCount
        .NumberFormat = "#,##0"
        .Name = "Issue Status"
    End With
Else
    ' just refresh the Pivot cache with the updated Range
    PTable.ChangePivotCache PCache
    PTable.RefreshTable
End If

End Sub