excel vba create pivot table -


i'm trying create pivot table in excel vba , fail so.

range("a5").select sheets.add  range("a5").select selection.currentregion.select  dataarea = "sheet1!r1c1:r" & selection.rows.count & "c" & selection.columns.count  activeworkbook.pivotcaches.create(sourcetype:=xldatabase, sourcedata:=dataarea, _     version:=xlpivottableversion10).createpivottable _     tabledestination:="sheet2!r3c1", tablename:="pivottable2", defaultversion _     :=xlpivottableversion10 

somehow dataarea doesn't accepted, suggestions?

you're trying create pivot table data area of single cell. if walk backwards through code eliminate .selects, you'll see you've got:

dataarea = "sheet1!r1c1:r" & range("a5").rows.count & "c" & range("a5").columns.count 

which translates

dataarea = "sheet1!r1c1:r" & "1" & "c" & "1" 

or

dataarea = "sheet1!r1c1:r1c1" 

if data runs through "a5", you'll want:

dataarea = "sheet1!r1c1:r5c1" 

but single column of data doesn't give excel pivot on...


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -