adding renaming deleting a sheet using macro

April 8, 2012 at 22:34:35
Specs: Windows XP

I am a beginner. I want to add few sheet to an excel files and at the same time rename them. Kindly also provide code to delete a sheet from a workbook.

See More: adding renaming deleting a sheet using macro

Report •

April 9, 2012 at 10:37:06
Sheets can be referred to by their position in the workbook (Sheets(1), Sheets(2), Sheets(Sheets.Count) for the last sheet, etc.) or by their name - Sheets("My Sheet")

They can also be referred to by a variable that represents a Name or number.

Here are some examples....

Sub SheetStuff()
'Add a sheet as the last sheet
   Sheets.Add After:=Sheets(Sheets.Count)
'Add a sheet as the second sheet
   Sheets.Add Before:=Sheets(3)
'Name / Rename Sheet2
   Sheets(2).Name = "My Second Sheet"
'Delete the first sheet
'Delete a sheet by name
   Sheets("My Second Sheet").Delete
'Delete Sheet 3 by variable
   varSht = 3
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •
Related Solutions

Ask Question