[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 480
  • Last Modified:

Excel Add new worsheet and rename it

Hi,

I need help in creating a excel macro that will delete a worksheet ("Data") then create a blank worksheet and re-name it back as "Data".

Thanks,

Cody
0
codysheilds
Asked:
codysheilds
  • 2
2 Solutions
 
PaulNSWCommented:
Sub Del_data_sheet()
    Application.DisplayAlerts = False
    Sheets("Data").Select
    ActiveWindow.SelectedSheets.Delete
    Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Data"
    Application.DisplayAlerts = True
End Sub

Open in new window


This will select and delete the Data sheet, then create a new sheet at the end called Data
0
 
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
Selecting the sheet is not required

Sub NewDataSheet()

    Application.DisplayAlerts = False
    Sheets("Data").Delete
    Sheets.Add After:=Sheets(Sheets.Count)
    ActiveSheet.Name = "Data"
    Application.DisplayAlerts = True
End Sub

Open in new window


cheers, teylyn
0
 
PaulNSWCommented:
so final code could be?

Sub Del_and_Create_Data()

    Application.DisplayAlerts = False
    Sheets("Data").Delete
    Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Data"
    Application.DisplayAlerts = True
End Sub

Open in new window

;)
0
 
codysheildsAuthor Commented:
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now