Monday, 15 August 2011

vba - How to select some selected Pivot table area? -



vba - How to select some selected Pivot table area? -

i trying select , re-create selected area of pivot table. able determine amount of area want , able display range in message box not objective. want re-create selected range. code looks this. want re-create values in range (toprow1,leftcoloumn:lastrow,rightcoloumn). fyi message box code don't need tell range no.

sub pivottablerangeareas() activesheet.pivottables(1) dim toprow1 long, toprow2 long, lastrow long dim leftcolumn long, rightcolumn long toprow2 = .tablerange2.row .tablerange1 toprow1 = .row lastrow = .rows.count + .row - 1 leftcolumn = .column rightcolumn = .columns.count + .column - 1 end msgbox "the pivot table named " & .name & vbcrlf & _ "occupies these range elements:" & vbcrlf & vbcrlf & _ "with study (page) field: " & vbcrlf & _ .tablerange2.address(0, 0) & vbcrlf & _ "without study (page) field: " & vbcrlf & _ .tablerange1.address(0, 0) & vbcrlf & vbcrlf & _ "first row, study (page) field: " & toprow2 & vbcrlf & _ "first row, without study (page) field: " & toprow1 & vbcrlf & _ "last row: " & lastrow & vbcrlf & _ "left column: " & leftcolumn & vbcrlf & _ "right column: " & rightcolumn, , "pivot table location." end end sub

i'm guessing it's values want copy? if so, seek starting - it'll set values sheet2 starting @ range a1. i'm not sure range pivot table want re-create - you'll have alter of suit:

sub copyrange() dim varray() variant 'copies values between (toprow1, leftcolumn) , (lastrow, rightcolumn) array varray = activesheet.range(cells(toprow1, leftcolumn), cells(lastrow, rightcolumn)).value 'pastes values array sheet2, starting @ a1 sheet2.range("a1").resize(ubound(varray, 1), ubound(varray, 2)).value = varray end sub

vba excel-vba

1 comment: