Results 1 to 5 of 5

Thread: Create copies of Worksheet (Master) based on a Range in another worksheet

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Posts
    8
    Rep Power
    0

    Create copies of Worksheet (Master) based on a Range in another worksheet

    Hello Experts

    A very happy New Year 2020 to all of you.

    I am creating a new MIS for my team of and need your help on it.

    I am using the below code to create the copies of a worksheet named "Master" around 20+ worksheets each month. I have a range of data in another Worksheet named "List of User" (Team members names) in column "K" say "K1:K25".

    The below code gives me any number of copies as I wish but, I need the new sheets to be named as per the Range in "List of User" Column "K" and it become dynamic so, that whenever a new name gets added to this list I need not worry while creating copies from the "Master" worksheet.

    Code:
    Public Sub DuplicateSheetMultipleTimes()
        Dim n As Integer
        On Error Resume Next
        n = InputBox("How many copies of the active sheet do you want to make?")
     
        If n >= 1 Then
            For numtimes = 1 To n
                ActiveSheet.Copy After:=ActiveWorkbook.Sheets(Worksheets.Count)
            Next
        End If
    End Sub
    Thanks all in Advance.
    Last edited by Deysam; 01-02-2020 at 03:18 PM.

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Hello Sumit
    Best wishes for the New Year to you too.

    I think I can see approximately what it is you want. But it would be a lot clearer if you could maybe give an example.

    Perhaps you can give us two workbooks.
    _ One should show us the situation Before the macro is run,
    and
    _ the other, the After, should look like what you want after the macro is run. In other words, you do manually to the After what you want the macro to do.

    Keep the data to the minimum that you need to demonstrate all possible scenarios. Desensitize any personal data. In other words make up your data, or change names etc. But the data should have a similar format and similar characteristics to real data.

    And tell us exactly what you did to get the After in its final form



    Alan

  3. #3
    Junior Member
    Join Date
    Dec 2019
    Posts
    8
    Rep Power
    0
    Thanks for your reply.

    I have attached a copy of the workbook that I am working with.

    Sheet "List of User" have the list of names that the macro should create new worksheets for. I have assign the vba code in "Sheet1 (Master).

    When somebody click "Ctrl+shift+Q" in the "Master" worksheet the input box appears asking for how many sheets to be created. I was trying to see if the macro can create only that much of named worksheets as in the "List of User" sheet have.

    e.g. I have 22 names in the "List of User" sheet so the macro should create named sheets (22 in number) name of the sheets shout be the Range "A" in "List of User".

    Thanks
    Again
    Attached Files Attached Files

  4. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Hi

    Try this

    Code:
    Option Explicit
    Public Sub DuplicateSheetMultipleTimes()
    Dim wsUsrs As Worksheet: Set wsUsrs = ThisWorkbook.Worksheets("List of User")
    Dim wsMstr As Worksheet: Set wsMstr = ThisWorkbook.Worksheets("Master")
    Dim rngStr As Range, rngUsrs As Range
     Set rngUsrs = wsUsrs.Range("A1:A" & wsUsrs.Cells.Item(wsUsrs.Rows.Count, 1).End(xlUp).Row & "")
        
        For Each rngStr In rngUsrs
         wsMstr.Copy After:=ThisWorkbook.Worksheets.Item(ThisWorkbook.Worksheets.Count)
         Let ActiveSheet.Name = rngStr.Value
        Next rngStr
        
        
    
    
    
    
    
    '    Dim n As Integer
    '    On Error Resume Next
    '    n = InputBox("How many copies of the active sheet do you want to make?")
    '
    '    If n >= 1 Then
    '        For numtimes = 1 To n
    '            ActiveSheet.Copy After:=ActiveWorkbook.Sheets(Worksheets.Count)
    '        Next
    '    End If
    End Sub
    Last edited by DocAElstein; 01-02-2020 at 08:38 PM.

  5. #5
    Junior Member
    Join Date
    Dec 2019
    Posts
    8
    Rep Power
    0
    Thanks a lot Alan.

    It's working just fine (**)

Similar Threads

  1. Replies: 5
    Last Post: 08-17-2017, 08:12 AM
  2. Worksheet Tab Name Based on Cell Value
    By tuna666 in forum Excel Help
    Replies: 2
    Last Post: 10-08-2013, 10:41 PM
  3. Print Nth Worksheet To Mth Worksheet using VBA
    By Ryan_Bernal in forum Excel Help
    Replies: 2
    Last Post: 02-28-2013, 06:57 PM
  4. Worksheet Change Event
    By jamilm in forum Excel Help
    Replies: 2
    Last Post: 12-29-2012, 12:06 AM
  5. Replies: 5
    Last Post: 12-05-2012, 03:01 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
  •