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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -