+ Reply to Thread
Results 1 to 19 of 19

Copy Sheet VBA

  1. #1
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Copy Sheet VBA

    Hi
    I have a Purchase Order sheet that I want to let the user copy a new order based on the template sheet (template will be hidden).
    I want the first new order sheet be named "1" and then the next new ones "2,3,4 etc" (all placed before "Shipping List").

    This is the code I have so far that works to a point:
    Please Login or Register  to view this content.

    I would like it to do the following:
    - Copy a new order (before Shipping List) and name it 1
    - Copy further new orders and name them sequentially
    - On the "Summary Sheet" automatically fill in the formulae (shown as REF! on the example attached) going down the table
    - Automatically say yes to all the Table rename error message boxes
    Attached Files Attached Files

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    I think this should do what you want.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    Ooops forgot the formulas on the summary sheet. I'll look at that in the next break.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    What is that formula supposed to be?

  5. #5
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy Sheet VBA

    Thanks dflak, that works but copies the summary sheet not the template order sheet.

    The formulas on the summary sheet that I want to update automatically show the following:
    > Column A (Order number) - the Purchase Order number at the top of each order sheet (cell - H3 on each order sheet)
    > Column C (Company) - Shows the company that the order is for (cell - F8 on each order sheet)
    > Column G (Actual costs) - Shows the actual cost for each order (cell - I36 on each order sheet)

    I also need it to automatically accept the Table name message box warnings.
    The template sheet needs to be hidden as well (I've left it visible for now).
    Kieran
    Last edited by kieranm105; 12-16-2016 at 06:53 AM.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    I also noticed that you would also like a hyperlink to the page from the Summary Sheet.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy Sheet VBA

    Thanks dflak, that works great.
    Kieran

  8. #8
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy Sheet VBA

    I have a quick question on this.
    It works great on everyone's PC apart from one! It pops up a runtime error and highlights this code.
    Please Login or Register  to view this content.
    When I looked at the hidden sheets, it had copied the Template sheet a few times and named them Template (2), Template (3) etc. But works perfectly on other PCs????

  9. #9
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    Hmmm. It shouldn't really matter if there are Template (3), Template (4) etc. As long as a Template (2) exists this line of code should take you to it.

    The code should not be creating the other copies, but they should not cause an error.

    Can you duplicate the error with a "fresh" copy of the spreadsheet?

  10. #10
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy Sheet VBA

    Hi dflak
    No it only happens on that one PC. Instead of copying the template and naming them correctly it just added more templates and then threw the error up.
    I tried it on mine and some other users PC's and it works fine. The only thing is that the PC in question had a recent upgrade to Win10 then had to have a factory reset back to Win8.1 as 10 wouldn't work.
    There could be some update missing?

  11. #11
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    I'm going to take a guess - take a look at the spelling. The code is looking for Template - space - (2). Could it be that the malfunctioning machine is looking for a spelling without the space.

    I'll relook at the code - I don't like the idea of depending on a name to make things work. This might be one of those rare instances where ActiveSheet is appropriate.

  12. #12
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    That took less time than I thought. Comment out the offending line and change the code to reflect the line highlighted in red below
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy Sheet VBA

    This gets even more confusing now!
    I've redone the code as above, which works on all the PC's as it should. But this one PC now copies the template and it is named 'Template (2)' and then renames the 'Shipping List' sheet to 1??
    I think his PC has some bugs in it somewhere!!
    Kieran

  14. #14
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    Are there differences in the versions of Excel?

    I am reluctant to depend on a sheet name unless I am sure what that sheet name is. I am also leery about using activesheet since Excel and I may have a difference of opinion on what the active sheet is. Apparently that is what is happening here. The program on the other machines thinks that the recently copied sheet is Template (2). On the exception machine, it thinks that Shipping List is the active sheet.

    What I can do is add the sheet after the last sheet so that I know that the last sheet in the book is the one I want to work with. Then after renaming it, move it to its proper position. This logic eliminates dependence on a name or active sheet. I'll give that a shot and get back to you.

  15. #15
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    Here is a new version with modified code
    Please Login or Register  to view this content.
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy Sheet VBA

    That worked, but hid the new sheet 1.
    We're checking for updates and reinstalling office 365 on that PC.
    Kieran

  17. #17
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Sheet VBA

    Nothing in the code says hide the sheet . Yeah, I think it's worth looking at office on that machine.

  18. #18
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy Sheet VBA

    This has been working great for a few months, now it is hiding the 5th sheet onwards on several pc's??
    The full code that I have is below.
    Any ideas?
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    03-16-2012
    Location
    Halifax, UK
    MS-Off Ver
    MS Office 365
    Posts
    206

    Re: Copy Sheet VBA

    This is now hiding the new sheet on everyone's pc. I've had a look and made it unhide the template sheet before copying it and then hiding it straight after.
    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 specific data from a sheet to temp sheet and copy temp sheet to new workbook
    By ANUARORA in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-18-2015, 11:58 AM
  2. how to copy specific data from a sheet to temp sheet and copy temp sheet toa new workbook?
    By NatashaKapoor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-18-2014, 09:01 AM
  3. Replies: 2
    Last Post: 01-18-2014, 10:54 PM
  4. Lookup Value from Sheet 4 in Sheet 2, if found copy Sheet 2 Active Row to Sheet 5
    By lgosso23 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-11-2013, 02:51 PM
  5. Replies: 1
    Last Post: 06-05-2013, 07:03 AM
  6. Replies: 1
    Last Post: 01-07-2013, 12:23 AM
  7. Replies: 11
    Last Post: 10-14-2012, 01:03 PM

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