Tuesday, October 6, 2009

Create New Sheets in Excel with Name from A to Z using VBA

Below is the VBA code [to be put into the macro] which creates sheets with name "A" to "Z" in a excel work book.

For my ease, I have created a button on the click of which all the sheets will be created.

To create the button, the code is :

Sub AddButton()
Set btn = ActiveSheet.Buttons.Add(0, 90, 100, 25)
btn.OnAction = "CreateNewSheet"
btn.Characters.Text = "CreateSheets"
End Sub


To create sheets:
Sub CreateNewSheet()
For i = 65 To 90
Sheets.Add.Name = Chr(i) ' Ascii representation of A to Z is 65 to 90
Next i
End Sub

No comments:

Total Pageviews