excel vba - Rename the newly created sheet based on active cell in Sheet1 -


i newbie @ vba , have problem solve, more simple, sure. here problem:

i have table company names in column a. want select cell company name, click button run macro creating new sheet based on template, , rename newly created sheet name of selected cell in sheet1 (company name).

the macro works, have problem renaming it. appriciated. comments on code in general useful. here code:

sub newsheet()  dim wb workbook dim ws worksheet dim activewb workbook dim filepath string  application.screenupdating = false application.displayalerts = false  on error resume next set wb = application.workbooks.open(filepath) wb.worksheets(1).copy after:=activewb.sheets(activewb.sheets.count) activewb.activate  activesheet.name = worksheets("arkusz1").activecell.value  wb.close false  application.screenupdating = true application.displayalerts = true end sub 

if need use activecell, can use code below:

dim shtname string shtname = activecell.value2 ' <-- save value of activecell  set wb = application.workbooks.open(filepath) wb.worksheets(1).copy after:=activewb.sheets(activewb.sheets.count)  ' rename sheet activewb.sheets(activewb.sheets.count).name = shtname 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -