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

Popular posts from this blog

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

javascript - Replicate keyboard event with html button -

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