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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,965
Messages
6,127,969
Members
449,414
Latest member
sameri

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