Hello,
I am creating a template for our ops team which I want to include a macro that will name the sheet based on a cell within the sheet. I have found how to name the cell but have had a hard time figuring out how to create a button that will create a new sheet within the workbook that contains the macros.
The excel doc contains static text in A1, A2 and A3. Users will fill out B1, B2 and B3 and the sheet will be renamed using the contents of cell B1.
I tried using a copy macro but that causes issues because it copies everything the user entered and because of that, it throws an error because two sheets cannot have the same name.
The macros which I am using to rename the cells is entered by right clicking on a sheet > View Code and pasting the following:
The copy code, in case anyone is wondering, is:
Thank you!
I am creating a template for our ops team which I want to include a macro that will name the sheet based on a cell within the sheet. I have found how to name the cell but have had a hard time figuring out how to create a button that will create a new sheet within the workbook that contains the macros.
The excel doc contains static text in A1, A2 and A3. Users will fill out B1, B2 and B3 and the sheet will be renamed using the contents of cell B1.
I tried using a copy macro but that causes issues because it copies everything the user entered and because of that, it throws an error because two sheets cannot have the same name.
The macros which I am using to rename the cells is entered by right clicking on a sheet > View Code and pasting the following:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)Set Target = Range("B1")
If Target = "" Then Exit Sub
Application.ActiveSheet.Name = VBA.Left(Target, 31)
Exit Sub
End Sub
The copy code, in case anyone is wondering, is:
Code:
Sub CopySheet_Beginning1()
ActiveSheet.Copy Before:=Worksheets(1)
End Sub
Thank you!