excel - How to get the newly inserted worksheet -
so have pivottable , in column c there field showing details each record using this
for i=7 10 data.range("c" & i).showdetail = true set wn = thisworkbook.worksheets(1) next
now works fine problem set wn = thisworkbook.worksheets(1)
assigns wn
first worksheet data.range("c" & i).showdetail = true
inserts new worksheet has details @ 1st or 2nd position. want know new worksheet inserted , assign wn
it.
do have make array or list keeps record of existing worksheets , check new 1 everytime? or there easy way determine newest worksheet in workbook irrespective of position.
look @ activesheet
. showdetail
creates new sheet , activates - set wn=activesheet
should work.
sub test() dim c range dim wrksht worksheet thisworkbook.worksheets("sheet2").pivottables(1) each c in .databodyrange.resize(, 1) c.showdetail = true set wrksht = activesheet debug.print wrksht.name next c end end sub
this link jon peltiers page on pivot tables should massive help... https://peltiertech.com/referencing-pivot-table-ranges-in-vba/
Comments
Post a Comment