+ Reply to Thread
Results 1 to 19 of 19

Duplicating sheets and modifying them automatically?

  1. #1
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Duplicating sheets and modifying them automatically?

    ok I have an excel workbook with 1 sheet in it. I have to duplicate the sheet about 25 times, change 2 variables in the sheet and rename each sheet. I can do this by using move/ copy and changing the variables and sheet names manually.

    My problem here is that i dont have 1 workbook, but 150 workbooks! so i have to do the copy-change variable-rename sheet about 3750 times :S

    so is there any way i could get excel to duplicate a sheet 25times, change a predefined variable each time,and rename the sheets( with some predefined rule) ?? I know this sounds far fetched, but it would help a lot if this could be done...

    anyone?

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Duplicating sheets and modifying them automatically?

    Yeah, really easy, would need to know the name of the sheet to copy, the address of the cells to change, the naming convention for the cells and the naming convention for the new pages.

    Uploading an example would be the most sensible thing to mkae this information clear.
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  3. #3
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Duplicating sheets and modifying them automatically?

    Yes, this is possible with a macro.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Duplicating sheets and modifying them automatically?

    ok so the variables which change are unitweight (cell C1), fi (cell F2) and ru (cell F1). The naming convention= Gamma = ' the value in cell C1', phi= 'the value in cell F2', ru='the value in cell F1'.

    im varying unitweight(C1) from 18 to 22 with a step of 2 (meaning ..18,20,22)
    for each value of unitweight, Im varying the value of fi(cell F2) from 15 to 27 with a step of 2 again
    and for each of these the value of ru.. 0, 0.2 and 10/C1

    you can use 'slope3.xls' to show me know to do it.

    thanks
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Duplicating sheets and modifying them automatically?

    Quote Originally Posted by Whizbang View Post
    Yes, this is possible with a macro.

    Please Login or Register  to view this content.



    this bit returns an error saying 'object does not support this action'. can you help?

    With Application.FileSearch
    .LookIn = "The path to folder containing your sheets"
    .SearchSubFolders = True
    .FileType = msoFileTypeExcelWorkbooks
    .Execute
    End With

  6. #6
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Duplicating sheets and modifying them automatically?

    Did you change the bit that says "The path to folder containing your sheets" to a valid, complete path (i.e. "C:\Projects\Customer Data\")?

    I just downloaded you example workbook and I will work on a custom macro.

    Just to clarify, you want sheets with the following variable values

    C1 F2 F1
    18 15 0
    18 15 0.2
    18 15 0.56
    18 17 0
    18 17 0.2
    18 17 0.56
    18 19 0
    18 19 0.2
    18 19 0.56
    18 21 0
    18 21 0.2
    18 21 0.56
    18 23 0
    18 23 0.2
    18 23 0.56
    18 25 0
    18 25 0.2
    18 25 0.56
    18 27 0
    18 27 0.2
    18 27 0.56
    20 15 0
    20 15 0.2
    20 15 0.5
    20 17 0
    20 17 0.2
    20 17 0.5
    20 19 0
    20 19 0.2
    20 19 0.5
    20 21 0
    20 21 0.2
    20 21 0.5
    20 23 0
    20 23 0.2
    20 23 0.5
    20 25 0
    20 25 0.2
    20 25 0.5
    20 27 0
    20 27 0.2
    20 27 0.5
    22 15 0
    22 15 0.2
    22 15 0.45
    22 17 0
    22 17 0.2
    22 17 0.45
    22 19 0
    22 19 0.2
    22 19 0.45
    22 21 0
    22 21 0.2
    22 21 0.45
    22 23 0
    22 23 0.2
    22 23 0.45
    22 25 0
    22 25 0.2
    22 25 0.45
    22 27 0
    22 27 0.2
    22 27 0.45
    Last edited by Whizbang; 07-22-2010 at 01:44 PM.

  7. #7
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Duplicating sheets and modifying them automatically?

    yes, this is it. I have entered the actual folder location instead of "The path to folder containing your sheets" the problem seems to be With Application.Filesearch. apparently it isnt available with newer versions of office. ( im running office 2010).. thanks!

  8. #8
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Duplicating sheets and modifying them automatically?

    Oh.. well, I can show you what it looks like in 2003. A 2010 expert will have to help you update it.

  9. #9
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Duplicating sheets and modifying them automatically?

    no problem

  10. #10
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Duplicating sheets and modifying them automatically?

    You seem to have it more-or-less tied up, but this should help:
    http://vbadud.blogspot.com/2006/12/d...ual-basic.html

  11. #11
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Duplicating sheets and modifying them automatically?

    using the code from vbadud..

    is sPath the location of the folder? and the following needs to be added?

    sPath= "C\........"

  12. #12
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Duplicating sheets and modifying them automatically?

    Lovi, a good way to test something in the VB Editor is the Immediate Window. Go to View -> Immediate Window

    Here you can type in code and have it immediately run. Type "msgbox(sPath)" to see what sPath's value is.

  13. #13
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Duplicating sheets and modifying them automatically?

    I haven't tested this, so... you may want to try it on test files first.

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Duplicating sheets and modifying them automatically?

    i tried it. at the moment its showing 'done' but without doing anything.

    i changed *.xls to *.xlsx
    replaced "master" with the sheet name

    i did msgbox for activeworkbook.path.. that was ok

    msgbox for sDir showed blank. is this normal? Shouldnt it be a list of files?

    also, where is Sht used?

  15. #15
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Duplicating sheets and modifying them automatically?

    Oops. Delete the Sht. I copied this code from another project of mine and didn't clean up the Dim statments appropriately.

    As for checking the value of sDir, I forgot to mention that you would need to be past the point where the variable is set. So, step into your project with F8, then keep pressing F8 until you pass the line that says "sDir = ". Then use your immediate window to check the value.

    As for it not doing anything, that is my fault. I missed the \ before the "*.xls". If you use your immediate window and do msg(ActiveWorkbook.Path & "*.xls"), you will see the problem. ActiveWorkbook.Path does not provide the trailing slash.

  16. #16
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Duplicating sheets and modifying them automatically?

    yes now it accesses the worksheet and copies the sheet. gamma(2) is created.. but there is a little problem in changing the name. it does not recognise gamma(2) . i can see it on the worksheet but vb cant. any idea how to work around that?

    also, could you check whether the 2003 code works please? im considering reverting to 2003.

  17. #17
    Registered User
    Join Date
    07-22-2010
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Duplicating sheets and modifying them automatically?

    yes now it accesses the worksheet and copies the sheet. gamma(2) is created.. but there is a little problem in changing the name. it does not recognise gamma(2) . i can see it on the worksheet but vb cant. any idea how to work around that?

    also, could you check whether the 2003 code works please? im considering reverting to 2003.

  18. #18
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Duplicating sheets and modifying them automatically?

    In the code there is a space between "Master" and "(2)". Delete this space.

    I'll test it tomorrow at work.

  19. #19
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Duplicating sheets and modifying them automatically?

    Here is the finished code. I tested it in 2003 and it works fine. I ended up moving the module into my Personal.xls. If the macro is being run from one of the files that needs to be processed, then the macro will stupidly try to open, then later save and close said file. Rather than work around this by doing an if statement, I just moved the macro to another workbook in another folder location.

    If this is the solution you were looking for, please rate this post. Thank you.

    Please Login or Register  to view this content.
    Last edited by Whizbang; 07-23-2010 at 09:26 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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