Excel VBA WorkSheet.Copy After Excel 2013 -
i want copy worksheet , place directly after sheet. having trouble when there hidden sheets involved.
using excel 2013 open new workbook. add sheet after "sheet1". rename "hiddensheet2" add sheet after "hiddensheet2". rename new sheet "sheet3" have "sheet1" - "hiddensheet1" - "sheet3" hide "hiddensheet1"
next run vba code:
sub test() dim ws1 worksheet set wst = sheets("sheet1") wst.copy after:=sheets(wst.index) end sub
the inserted sheet placed after "hiddensheet2" , not after "sheet1". found copied sheet becomes active sheet.
get handle on last worksheet copied worksheet.copy
vba copy sheet end of workbook (with hidden worksheets)
but problem need sheet remain in specific order.
thanks
edit:
sub test() dim ws1 worksheet set wst = sheets("sheet1") wst.copy after:=sheets(wst.index) thisworkbook.activesheet.move after:=sheets(wst.index) end sub
this doesn't new sheet directly after "sheet1" either.
existing code can added
sub test() dim ws1 worksheet set wst = sheets("sheet1") wst.copy after:=sheets(wst.index) thisworkbook.activesheet.move after:=sheets(wst.index)
if (activesheet.index - wst.index - 1) <> 0 sheets(wst.index + 1).visible = true activesheet.move after:=wst sheets(wst.index + 2).visible = false end if
end sub
Comments
Post a Comment