How to create new sheet in workbook named from a cell in another sheet

Rhodie72

Well-known Member
Joined
Apr 18, 2016
Messages
573
I am wanting to add a new sheet of data and name the new sheet by the text in another sheet. I'm not looking for a dynamic name change as it is just copy and paste data going into it. I keep geting a debug error... lol.

And whilst writing this I realised I was being stupid and created the solution, so here's the answer to my question which I hope will help somebody, somewhere, achieve something useful in their life.
VBA Code:
Sub Create_New_Payslip()
'
'
Dim MyName As String

    MyName = Sheets("UTF-8").Range("C26").Text
    Sheets.Add After:=ActiveSheet
    ActiveSheet.Name = MyName
    Sheets("UTF-8").Range("A1:K27").Cut
    With Sheets(MyName)
        .Paste
        .Columns("A:K").EntireColumn.AutoFit
    End With
    Sheets("UTF-8").Range("A1").Select

    MyName =empty 'Memory management
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Replace this line
VBA Code:
MyName = Sheets("UTF-8").Range("C26").Text
with
VBA Code:
MyName = CStr(Sheets("UTF-8").Range("C26").Value)
 
Upvote 1

Forum statistics

Threads
1,215,153
Messages
6,123,325
Members
449,097
Latest member
gameover8

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top