Friday, 4 December 2020

How To Create A New Sheet with Name in VBA


In our previous blog post, you learned about how to insert a new sheet before and after from any particular sheet by VBA.


Now in this post, you will learn about how to insert a new sheet with name from VBA macro. 

Here we are going to use the following code:-


Sub insert_new_sheet_with_name()

Sheets.Add.Name = "My Data"

End Sub


In the below image, you can see how this macro works.

When we execute this macro, our new sheet “My Data” added, see in the image below.






This one is the first method to insert a new sheet by VBA.


How To Insert A New Sheet With Name By Cell Range


In this method, you will learn about how to insert a new sheet by a cell value.

See in the below image, we have a cell value as “Excelnsg” in range (“A1”).

See in the below image-





Now we will create a new sheet in Excel by giving a name from the cell value.


Our sheet name is “Main” where our range “A1” has a value as “Excelnsg”.


Now we will use the following code to insert a new sheet with the name from a cell.


Sub insert_new_sheet_with_name_2()

Sheets.Add.Name = Range("A1").Value

End Sub


Write the above code in the VBA module and press 'F5' to execute the code and see the result in the below image.






After executing the code, see the result in the above picture. A new sheet with named as 'Range("A1") which is 'Excelnsg'.


So you learn, how to insert a new sheet in Excel with name by VBA macro.


I hope you find this tutorial useful.


Please feel free to post your comment and suggestion in the comment box below.

Thanks

Narendra.




Related Post








No comments:

Post a Comment

Featured post

Pivot Tables