PDA

View Full Version : Insert many worksheets and name



Zaigham
09-11-2014, 10:03 PM
Hi
I want to insert many new worksheets in a workbook (near about 100). Problem is naming each sheet manually. I need a macro which can do this for me by assigning different names to newly inserted worksheets from a given list.
Regards
Zaigham

Admin
09-12-2014, 07:42 AM
Hi


Option Explicit

Sub kTest()

Dim NameList, i As Long, msg As String

Application.ScreenUpdating = False
With ThisWorkbook
NameList = .Worksheets("Sheet1").Range("a2:a100") 'adjust this list
On Error Resume Next
For i = 1 To UBound(NameList, 1)
If Len(NameList(i, 1)) Then
.Worksheets.Add().Name = NameList(i, 1)
If Not Err.Number = 0 Then
msg = msg & vbLf & NameList(i, 1)
Err.Clear
End If
End If
Next
End With
If Len(msg) Then
MsgBox "The following names are not valid to rename the sheets." & vbLf & msg, vbInformation
End If
Application.ScreenUpdating = True

End Sub

Zaigham
09-12-2014, 07:38 PM
Hi Admin

It works fine. Just inserts sheets in descending order and it is not a big problem. I am really thankful to you.:)

Rick Rothstein
09-12-2014, 08:40 PM
Hi Admin

It works fine. Just inserts sheets in descending order and it is not a big problem. I am really thankful to you.:)
If you want the order reversed, then change Admin's For statement to this...


For i = UBound(NameList, 1) To 1 Step -1

Zaigham
09-13-2014, 02:54 PM
Now it works very fine. Thank you very much.%D