How to add a named sheet at the end of all Excel sheets

0 votes

I am trying to add an Excel sheet named "Temp" at the end of all existing sheets, but this code is not working:

Private Sub CreateSheet()
    Dim ws As Worksheet
    ws.Name = "Tempo"
    Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
End Sub

Can you please let me know why?

Apr 4, 2022 in Database by gaurav
• 23,260 points
670 views

1 answer to this question.

0 votes

This will allow you to choose whether to overwrite or save a tab with the same name.
Place the sheet at the end of all tabs or right next to the one you're working on.
Choose from the New and Active sheets.

Private Sub CreateSheet()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets.Add(After:= _
             ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
    ws.Name = "Tempo"
End Sub

answered Apr 4, 2022 by Edureka
• 13,690 points

edited Mar 5
0 votes

Kindly use this one liner:

Sheets.Add(After:=Sheets(Sheets.Count)).Name = "new_sheet_name"

Or use a With clause to avoid repeatedly calling out your object

Private Sub CreateSheet()
    Dim ws As Worksheet
    With ThisWorkbook
        Set ws = .Sheets.Add(After:=.Sheets(.Sheets.Count))
        ws.Name = "Tempo"
    End With
End Sub
answered Apr 5, 2022 by gaurav
• 23,260 points

Related Questions In Database

0 votes
1 answer
0 votes
0 answers

How to get address, Column Name and Row Name of all marked rows in Excel table as rows in new worksheet

 need the row/column combinations marked with an ...READ MORE

Feb 24, 2022 in Database by Edureka
• 13,690 points
2,196 views
0 votes
1 answer
0 votes
1 answer

How to get the "Name Box" name of an Excel cell?

By typing in the Name Box, you ...READ MORE

answered Mar 15, 2022 in Database by gaurav
• 23,260 points
5,826 views
0 votes
0 answers

How to split a string of text in excel based on a given word?

I have a list of combinations of ...READ MORE

Apr 4, 2022 in Database by gaurav
• 23,260 points
603 views
0 votes
0 answers

How to select the last record of a table in SQL?

Here is an example of code that ...READ MORE

Aug 23, 2022 in Database by Kithuzzz
• 38,000 points
1,333 views
0 votes
1 answer

How to retrieve the current version of a MySQL database management system (DBMS)?

Many responses advise using mysql —version. But ...READ MORE

answered Sep 20, 2022 in Database by narikkadan
• 63,600 points
831 views
0 votes
1 answer

How to view the XML form of an Excel file?

Excel is a spreadsheet programme. Click File->Open in ...READ MORE

answered Mar 25, 2022 in Database by Edureka
• 13,690 points
6,572 views
0 votes
1 answer

How to enter a series of numbers automatically in Excel

Excel, unlike other Microsoft Office programmes, does ...READ MORE

answered Apr 4, 2022 in Database by Edureka
• 13,690 points
829 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP