{"id":12070,"date":"2011-10-11T11:16:59","date_gmt":"2011-10-11T11:16:59","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=46"},"modified":"2011-10-11T11:16:59","modified_gmt":"2011-10-11T11:16:59","slug":"add-a-sheet-using-excel-macro","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2011\/10\/add-a-sheet-using-excel-macro\/","title":{"rendered":"Add a Sheet using Excel Macros"},"content":{"rendered":"
Adding a sheet in Already existing workbook is very easy. It can be done manually easily. Here we are going to learn, how to add a Sheet in an already existing workbook using Excel Macro. For doing so, there can be many possibilities. In some cases, you might just want to add a new sheet (without any formatting) with a name given by user. In this case you can just add a new sheet using macro and then rename the sheet name with the given name by user. <\/p>\n Adding a sheet in Already existing workbook is very easy. It can be done manually easily. Here we are going to learn, how to add a Sheet in an already existing workbook using Excel Macro. For doing so, there can be many possibilities. For example:\u00a0 we might want to add a new sheet always […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1246,1674],"tags":[],"class_list":["post-12070","post","type-post","status-publish","format-standard","hentry","category-macro","category-excel-macro-basics"],"yoast_head":"\n
\n
\nFor example:\u00a0 <\/strong> we might want to add a new sheet always with certain format. In this case, either we first add a new Sheet to the workbook without any formatting and then do the same formatting using macro, or make a Template (Sheet) which has exactly the same format what you want in each sheet and then copy the same Template each time and then rename the sheet name with the given name.<\/p>\n
\n
\nNote: <\/strong><\/span> While adding a new Sheet in Excel, MS Excel never ask for a name of that new Sheet; It always gives it’s own generated name like Sheet 1, Sheet 2, Sheet 3….etc. So when you want to add a New sheet with your own Name, First add a Sheet and then Rename it with your given Name. This is the reason, you can see in both the below example we are first adding a new Sheet and then renaming it.<\/em>
\n <\/p>\ni) When you have already built template for the sheet: <\/h2>\n
\r\nSub addsheet(VariableSheetName)\r\n' *****************************************************\r\n' Before adding any sheet in to workbook we need\r\n' to make sure that there is no sheet already there\r\n' in the work book with same name.\r\n' *****************************************************\r\nDim SheetExists as Boolean\r\nSheetExists = False\r\nFor Each Sheet In Sheets\r\nIf Ucase(Sheet.Name ) = Ucase(VariableSheetName) Then\r\nSheetExists = True\r\nMsgbox(\"This Sheet already exists\")\r\nEnd If\r\nNext Sheet\r\nIf (SheetExists = False) Then\r\nWorksheets(\"Expences-Template\").Copy After:=Worksheets(\"Expences-Template\")\r\nWorksheets(\"Expences-Template (2)\").Name = VariableSheetName\r\nEnd If\r\nWorksheets(VariableSheetName).Activate\r\nEnd Sub\r\n<\/code><\/pre>\n
ii) When you have to simply add a sheet with desired name<\/h2>\n
\r\nSub AddSheet(VariableSheetName)\r\n' *****************************************************\r\n' Before adding any sheet in to workbook we need\r\n' to make sure that there is no sheet already there\r\n' in the work book with same name.\r\n' *****************************************************\r\nDim SheetExists as Boolean\r\nSheetExists = False\r\nFor Each Sheet In Sheets\r\nIf Ucase(Sheet.Name ) = Ucase(VariableSheetName) Then\r\nSheetExists = True\r\nMsgBox(\"This Sheet already exists\")\r\nEnd If\r\nNext Sheet\r\nIf (SheetExists = False) Then\r\nWorksheets.Add().Name = VariableSheetName\r\nWorksheets(VariableSheetName).Select\r\nEnd Sub\r\n<\/code><\/pre>\n<\/span>","protected":false},"excerpt":{"rendered":"