Results 1 to 5 of 5

Thread: Insert many worksheets and name

  1. #1
    Junior Member Zaigham's Avatar
    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0

    Insert many worksheets and name

    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

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Code:
    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
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Junior Member Zaigham's Avatar
    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0
    Hi Admin

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

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by Zaigham View Post
    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...

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

  5. #5
    Junior Member Zaigham's Avatar
    Join Date
    Mar 2013
    Posts
    13
    Rep Power
    0
    Now it works very fine. Thank you very much.

Similar Threads

  1. Delete worksheets without loop
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 5
    Last Post: 03-04-2014, 07:29 PM
  2. Calculating data from other Worksheets
    By Ribice in forum Excel Help
    Replies: 4
    Last Post: 12-27-2013, 11:32 AM
  3. Copy Automatically Between Two Worksheets
    By marreco in forum Excel Help
    Replies: 0
    Last Post: 08-27-2012, 04:48 PM
  4. Protecting Elements in Worksheets
    By LeeL in forum Excel Help
    Replies: 1
    Last Post: 07-29-2011, 07:32 AM
  5. Merge Multiple Worksheets into One
    By Rasm in forum Excel Help
    Replies: 2
    Last Post: 05-04-2011, 04:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •