excel - VBA Create Multi Pivot Table -


code running no error pop-out, no pivot table showing in tab apple# , banana#.there must wrong. hope check code.. or teach me better way this.

sub tabletesting()  dim papplesheet, pbananasheet worksheet dim dapplesheet, dbananasheet worksheet dim applecache1, applecache2, bananacache1, bananacache2 pivotcache dim appletable1, appletable2, bananatable1, bananatable2 pivottable dim papplerange, pbananarange range dim lastrowapple, lastrowbanana long dim lastcolapple, lastcolbanana long  'apple  on error resume next  set papplesheet = worksheets("apple#") set dapplesheet = worksheets("apple")  lastrowapple = dapplesheet.cells(rows.count, 1).end(xlup).row lastcolapple = dapplesheet.cells(1, columns.count).end(xltoleft).column set papplerange = dapplesheet.cells(1, 1).resize(lastrow, lastcol)   set applecache1 = activeworkbook.pivotcaches.create _ (sourcetype:=xldatabase, sourcedata:=papplerange). _ createpivottable(tabledestination:=papplesheet.cells(1, 1), _ tablename:="applestrtable1")  set appletable1 = applecache1.createpivottable _ (tabledestination:=papplesheet.cells(1, 1), tablename:="applestrtable1")   activesheet.pivottables("applestrtable1").pivotfields("sender") .orientation = xlrowfield .position = 1 end   activesheet.pivottables("applestrtable1").pivotfields("amount") .orientation = xldatafield .position = 1 .function = xlsum .numberformat = "#,##0" .name = "amount "   end  activesheet.pivottables("applestrtable1").pivotfields("amount") .orientation = xldatafield .position = 1 .function = xlcount .numberformat = "#,##0" .name = "item "  end   set applecache2 = activeworkbook.pivotcaches.create _ (sourcetype:=xldatabase, sourcedata:=papplerange). _ createpivottable(tabledestination:=papplesheet.cells(1, 6), _ tablename:="applestrtable2")  set appletable2 = applecache2.createpivottable _ (tabledestination:=papplesheet.cells(1, 1), tablename:="applestrtable2")   activesheet.pivottables("applestrtable2").pivotfields("sender") .orientation = xlrowfield .position = 1 end  activesheet.pivottables("applestrtable2").pivotfields("color") .orientation = xlrowfield .position = 2 end   activesheet.pivottables("applestrtable2").pivotfields("amount") .orientation = xldatafield .position = 1 .function = xlsum .numberformat = "#,##0" .name = "amount "   end  activesheet.pivottables("applestrtable2").pivotfields("amount") .orientation = xldatafield .position = 1 .function = xlcount .numberformat = "#,##0" .name = "item "  end  'banana  on error resume next  set pbananasheet = worksheets("banana#") set dbananasheet = worksheets("banana")  lastrowbanana = dbananasheet.cells(rows.count, 1).end(xlup).row lastcolbanana = dbananasheet.cells(1, columns.count).end(xltoleft).column set pbananarange = dbananasheet.cells(1, 1).resize(lastrow, lastcol)   set bananacache1 = activeworkbook.pivotcaches.create _ (sourcetype:=xldatabase, sourcedata:=pbananarange). _ createpivottable(tabledestination:=pbananasheet.cells(1, 1), _ tablename:="bananastrtable1")  set bananatable1 = bananacache1.createpivottable _ (tabledestination:=pbananasheet.cells(1, 1), tablename:="bananastrtable1")   activesheet.pivottables("bananastrtable1").pivotfields("sender") .orientation = xlrowfield .position = 1 end   activesheet.pivottables("bananastrtable1").pivotfields("amount") .orientation = xldatafield .position = 1 .function = xlsum .numberformat = "#,##0" .name = "amount "   end  activesheet.pivottables("bananastrtable1").pivotfields("amount") .orientation = xldatafield .position = 1 .function = xlcount .numberformat = "#,##0" .name = "item "  end   set bananacache2 = activeworkbook.pivotcaches.create _ (sourcetype:=xldatabase, sourcedata:=pbananarange). _ createpivottable(tabledestination:=pbananasheet.cells(1, 6), _ tablename:="bananastrtable2")  set bananatable2 = bananacache2.createpivottable _ (tabledestination:=pbananasheet.cells(1, 1), tablename:="bananastrtable2")   activesheet.pivottables("bananastrtable2").pivotfields("sender") .orientation = xlrowfield .position = 1 end  activesheet.pivottables("bananastrtable2").pivotfields("color") .orientation = xlrowfield .position = 2 end   activesheet.pivottables("bananastrtable2").pivotfields("amount") .orientation = xldatafield .position = 1 .function = xlsum .numberformat = "#,##0" .name = "amount "   end  activesheet.pivottables("bananastrtable2").pivotfields("amount") .orientation = xldatafield .position = 1 .function = xlcount .numberformat = "#,##0" .name = "item "  end 

end sub


Comments

Popular posts from this blog

javascript - Replicate keyboard event with html button -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Web audio api 5.1 surround example not working in firefox -