+ Reply to Thread
Results 1 to 10 of 10

Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column A

  1. #1
    Registered User
    Join Date
    03-27-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    6

    Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column A

    Friends, I need help with the below.

    How do I run my code automatically on Opening the file...I wrote the macro to copy Sheet "Template" and create multiple sheets based on a Column list ("HM") of values in sheet "Data"....the macro runs within the code but does not run when I open the file even with the Private Sub Workbook_Open() command. I have my list in the "Data" sheet column "HM" and the sheet to be copied and created is the "Template". I inserted a button to run it but want to run it automatically on opening. Also the button click only works when I place the Button in the Data Sheet. I want the button to be placed in the Template Sheet. Please help. First priority is to make it run automatically on opening

    Here is my code created under Module1:

    Sub NewSheets()

    Dim i As Integer
    Dim ws As Worksheet
    Dim sh As Worksheet
    Set ws = Sheets("Template")
    Set sh = Sheets("Data")
    Application.ScreenUpdating = 0

    For i = 5 To Range("HM" & Rows.Count).End(xlUp).Row
    Sheets("Template").Copy After:=sh
    ActiveSheet.Name = sh.Range("HM" & i).Value

    Next i
    End Sub

    And at the workbook level I used the below code:

    Private Sub Workbook_Open()
    NewSheets
    End Sub
    Show less
    Last edited by abyk; 03-27-2017 at 08:49 PM.

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Try This
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    03-27-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    6

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Hey Friend this is not working...I placed it in the Workbook and module both. Still doesnt run........But runs when i clink on the button click. Cant figure out wheres the issue. Thanks for your time to look into it. Do you have any other suggestion.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Sowy ...Should be this...Put it in a Module. Why don't you upload your file so that we can have a look.
    Please Login or Register  to view this content.
    Last edited by sintek; 03-28-2017 at 08:01 AM.

  5. #5
    Registered User
    Join Date
    03-27-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    6

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Up;oaded the file. Tried putting the code in the module still doesnt run.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Hi abyk

    Here you go. i deleted your command button on sheet. On open, your code will run automatically.
    Code in two different modules.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-27-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    6

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Thanks my friend. It is working.

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Pleasure... Thanks for the rep points

  9. #9
    Registered User
    Join Date
    03-27-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    6

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Hey Friend,

    It stopped working again. It only worked first time when I opened.

  10. #10
    Registered User
    Join Date
    03-27-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    6

    Re: Copy Sheet 2 and create and rename multiple sheets based on the list in Sheet 1 Column

    Attaching the File Again. Could you please check and Help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy Template Sheet and rename the new sheets based on a list in another sheet
    By SaadKiji in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2016, 11:47 AM
  2. [SOLVED] Create new sheets from master sheet based on multiple column criteria
    By hamidxa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2015, 02:44 PM
  3. Replies: 3
    Last Post: 10-01-2014, 01:49 PM
  4. Replies: 2
    Last Post: 10-08-2013, 02:58 PM
  5. [SOLVED] Macro To Create New Sheet (and rename it) based on unique values in column
    By himynameisiain in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-31-2013, 08:59 AM
  6. Create A Copy To A New Sheet & Rename Sheet Based on Cell Value
    By delicard in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 07-25-2013, 08:56 PM
  7. Replies: 0
    Last Post: 07-16-2013, 01:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1