Name new Worksheet with range from LastRow on list

jo_hivera

New Member
Joined
May 29, 2020
Messages
28
Office Version
  1. 2019
Platform
  1. Windows
Good Afternoon,

I'm currently having trouble with my code to name a new sheet (when created) with the value from column A, using the last row used as guidance.
The userform adds the data to the list and it should copy a worksheet named "Template" and rename itself to the last info added on column A on the "Checklist" sheet.

I've been teaking it and this i what i have so far:
VBA Code:
Private Sub SUBMIT1_Click()
Dim LR As Long
Dim ws As Worksheet
Set ws = Worksheets("Checklist")
'Determine LR

  LR = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
  
'Transfer information

Cells(LR, 1).Value = NAME1.Value
Cells(LR, 2).Value = CODE1.Value
Cells(LR, 3).Value = ID1.Value
Cells(LR, 4).Value = LEVEL1.Value
Cells(LR, 5).Value = DEPT1.Value
Cells(LR, 6).Value = DATE1.Value

NAME1.Value = ""
CODE1.Value = ""
ID1.Value = ""
LEVEL1.Value = ""
DEPT1.Value = ""
 
'When you submit data, it creates new employee sheet,
'using the "Template" Worksheet and naming it after them
  Worksheets("Template").Copy After:=Worksheets(Worksheets.Count)
  Worksheets(Worksheets.Count).NAME = ws.NAME(ws.Cells(Rows.Count, 1)).End(xlUp).Row + 1

  Worksheets("Checklist").Activate

End Sub

The problem lies mainly in this section:
VBA Code:
'When you submit data, it creates new employee sheet,
'using the "Template" Worksheet and naming it after them
  Worksheets("Template").Copy After:=Worksheets(Worksheets.Count)
  Worksheets(Worksheets.Count).NAME = ws.NAME(ws.Cells(Rows.Count, 1)).End(xlUp).Row + 1

I'm adding screenshots of the sheets, the code i started with and the code i currently have for context.
All suggestions are welcome!
Thank you!
 

Attachments

  • Q1_01.PNG
    Q1_01.PNG
    127.4 KB · Views: 6
  • Q1_02.PNG
    Q1_02.PNG
    17.4 KB · Views: 7
  • Q1_03.PNG
    Q1_03.PNG
    31.8 KB · Views: 7

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.
What are you trying to do with ws.NAME here?
VBA Code:
Worksheets(Worksheets.Count).NAME = ws.NAME(ws.Cells(Rows.Count, 1)).End(xlUp).Row + 1
Shouldn't it be like this?
Code:
Worksheets(Worksheets.Count).Name = ws.Cells(Rows.Count, 1)).End(xlUp).Row
 
Upvote 0
What are you trying to do with ws.NAME here?
VBA Code:
Worksheets(Worksheets.Count).NAME = ws.NAME(ws.Cells(Rows.Count, 1)).End(xlUp).Row + 1
Shouldn't it be like this?
Code:
Worksheets(Worksheets.Count).Name = ws.Cells(Rows.Count, 1)).End(xlUp).Row

Hey Norie!
Thanks in advance for the help!
I didn't know if I needed to reference .NAME to name the sheet.
When i submit the userform data it should make a copy of the "Template" sheet and name itself after the Name on the employee list.
I tried your code, but the sheet named itself after the row the last name was added, for some reason.
It should look like the picture, in attachment.
 

Attachments

  • Q1_04.PNG
    Q1_04.PNG
    37.3 KB · Views: 11
Upvote 0
I'm a little confused, what do you want to name the worksheet?

Will it be with the value in the textbox NAME1?
 
Upvote 0
Try this.
Code:
Private Sub SUBMIT1_Click()
Dim LR As Long
Dim ws As Worksheet
Dim strName As String

    Set ws = Worksheets("Checklist")
    'Determine LR

    LR = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1

    'Transfer information
    With ws
        .Cells(LR, 1).Value = NAME1.Value
        .Cells(LR, 2).Value = CODE1.Value
        .Cells(LR, 3).Value = ID1.Value
        .Cells(LR, 4).Value = LEVEL1.Value
        .Cells(LR, 5).Value = DEPT1.Value
        .Cells(LR, 6).Value = DATE1.Value
    End With
    
    strName = NAME1.Value
    
    NAME1.Value = ""
    CODE1.Value = ""
    ID1.Value = ""
    LEVEL1.Value = ""
    DEPT1.Value = ""

    'When you submit data, it creates new employee sheet,
    'using the "Template" Worksheet and naming it after them
    Worksheets("Template").Copy After:=Worksheets(Worksheets.Count)
    Worksheets(Worksheets.Count).Name = strName

    Worksheets("Checklist").Activate

End Sub
 
Upvote 0
Try this.
Code:
Private Sub SUBMIT1_Click()
Dim LR As Long
Dim ws As Worksheet
Dim strName As String

    Set ws = Worksheets("Checklist")
    'Determine LR

    LR = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1

    'Transfer information
    With ws
        .Cells(LR, 1).Value = NAME1.Value
        .Cells(LR, 2).Value = CODE1.Value
        .Cells(LR, 3).Value = ID1.Value
        .Cells(LR, 4).Value = LEVEL1.Value
        .Cells(LR, 5).Value = DEPT1.Value
        .Cells(LR, 6).Value = DATE1.Value
    End With
   
    strName = NAME1.Value
   
    NAME1.Value = ""
    CODE1.Value = ""
    ID1.Value = ""
    LEVEL1.Value = ""
    DEPT1.Value = ""

    'When you submit data, it creates new employee sheet,
    'using the "Template" Worksheet and naming it after them
    Worksheets("Template").Copy After:=Worksheets(Worksheets.Count)
    Worksheets(Worksheets.Count).Name = strName

    Worksheets("Checklist").Activate

End Sub

Works wonders! Thank you so much!!
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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