+ Reply to Thread
Results 1 to 9 of 9

Copy worksheet X times based on Cell Values in Sheet [See added Example] :)

  1. #1
    Registered User
    Join Date
    08-25-2017
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    19

    Copy worksheet X times based on Cell Values in Sheet [See added Example] :)

    I have a workbook with a sheet called "data". In this sheet the data is placed in cell B12 to AD150. Column B has values from 1 to 138.

    Now I made a worksheet which represents all the data of one row from the worksheet data. The name of that worksheet is called "1", the same value as the cell value in column B of that row.

    I would like to have a macro which copies worksheet "1" as much as times as there are filled rows in column B in the worksheet "data". The names of the copied worksheets must be the same as the data in column B from the worksheet "Data".

    Somebody who can handle this challange for me??


    EDIT: now with example
    Attached Files Attached Files
    Last edited by heinzpol; 02-12-2020 at 10:53 AM. Reason: Example added

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Copy worksheet X times based on Cell Values in Sheet

    Do you want to make the copy of sheet"1" with the same cells contents ?
    Sheet"1" is for cell B12 ?
    Does value"1" exists in column "B", if yes we will have twice sheet "1" and conflict ...!
    - Battle without fear gives no glory - Just try

  3. #3
    Registered User
    Join Date
    08-25-2017
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    19

    Re: Copy worksheet X times based on Cell Values in Sheet

    Thanks for your reply, I will post an example....

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Copy worksheet X times based on Cell Values in Sheet

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-25-2017
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    19

    Re: Copy worksheet X times based on Cell Values in Sheet

    Thanks, but this one gives an error...

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Copy worksheet X times based on Cell Values in Sheet

    Next time, let people know what the error is.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-25-2017
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    19

    Re: Copy worksheet X times based on Cell Values in Sheet

    Thanks this works great!!

    Only one thing that bothers me now and that's when I make changes in the data sheet en run the macro again an error occurs. See pict
    Attachment 662368

    That's because the sheets with the names already exist. I editted it and now it works fine! Thanks for your help!!

    Please Login or Register  to view this content.
    Last edited by heinzpol; 02-12-2020 at 11:14 AM.

  8. #8
    Registered User
    Join Date
    08-25-2017
    Location
    Netherlands
    MS-Off Ver
    2016
    Posts
    19

    Re: Copy worksheet X times based on Cell Values in Sheet

    Unfortunately the code does not work in the workbook I want to implement it in. After running the macro an error message shows up which says the name already exists. See attached pictures.

    I cannot figure out what to change in the code.

    Attachment 662373
    Attachment 662374
    Attachment 662375

    [EDIT]: Found out myself: the data in my sheet was one row up, so I changed "i = 12 To lr" in "i = 13 To". Now it works fine!!

    Thanks again for helping Jolivanus!
    Last edited by heinzpol; 02-12-2020 at 12:01 PM.

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Copy worksheet X times based on Cell Values in Sheet

    Re: the data in my sheet was one row up
    If that could be a future problem, you could use
    Please Login or Register  to view this content.
    and use it later as
    Please Login or Register  to view this content.
    As long as the cell above the 1 is the cell that has "Nr."
    Your cleaned up code would look like
    Please Login or Register  to view this content.

+ 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. Copy row values 'x' number of times based on cell value
    By hoss88 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2019, 09:57 AM
  2. Use VBA to copy sheet number of times based on cell?
    By ColdWater in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2017, 09:40 PM
  3. Replies: 2
    Last Post: 01-23-2016, 01:16 PM
  4. Worksheet Change to copy from a sheet based on values from data validation list
    By Onenguyen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2012, 10:23 AM
  5. Copy and Paste (Same worksheet) based on cell values
    By muckem333 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2011, 04:43 PM
  6. Copy Worksheet X Times Based on Cell Value
    By PY_ in forum Excel General
    Replies: 2
    Last Post: 01-04-2011, 04:10 PM
  7. copy sheet a # of times based on cell value
    By nuver in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2005, 03:34 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