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
420 views

1 answer to this question.

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
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,670 points
1,726 views
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
4,000 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,670 points
5,162 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,670 points
552 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
250 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,010 points
833 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,420 points
406 views
0 votes
1 answer
0 votes
1 answer
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