+ Reply to Thread
Results 1 to 5 of 5

Copy First sheet button

  1. #1
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Copy First sheet button

    Hello, I have the code below to copy sheet1 and move it to the end renaming it and that part works well, however I get an error message (1004 That name is already taken. Try a different one) if I try and create another copy. What could be added to the code below to check if the name/date exists and if it does just add a number at the end like 2 then 3 and so on.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Copy First sheet button

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Re: Copy First sheet button

    @Logit thank You.... Your code creates the new sheet correctly but its not copying the first sheet using:

    Sheets(1).Copy After:=Sheets(Sheets.Count) 'Refers to first sheet and copies.

    Where would I add that back in? On a side note, when copying using Sheets(1) which I read that refers to the first sheet in the workbook, how do you refer to the sheet a different way? The sheet is Sheet13(Name Of sheet).

    I tried the below code but I get an error 424 Object required

    Set wSheet = Sheets(1).Copy(After:=Sheets(Sheets.Count))
    Last edited by oxicottin; 03-20-2024 at 06:26 PM. Reason: added info

  4. #4
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,223

    Re: Copy First sheet button

    Sheets can be referenced in at least two ways:
    -or by means of an index (the order of the sheets in the workbook)
    Please Login or Register  to view this content.
    -or by the name of the sheet
    Please Login or Register  to view this content.
    The following code copies the sheet named "Sheet13", inserts it last, renames it to the new name, and possibly increments the new name if one already exists:
    Please Login or Register  to view this content.
    Artik

  5. #5
    Registered User
    Join Date
    02-18-2006
    Location
    WV
    MS-Off Ver
    2003,2007,2010
    Posts
    69

    Re: Copy First sheet button

    Thanks @Logit and @Artic for the code it works great!

+ 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. Replies: 0
    Last Post: 01-10-2023, 09:04 AM
  2. [SOLVED] On button click > Copy select cells from Sheet 1 > Paste to Sheet 2 in new row
    By elite-fusion in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-25-2022, 07:01 PM
  3. [SOLVED] Command button to copy cells from one sheet and paste in second sheet
    By waratdenison in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-22-2014, 02:53 PM
  4. Button to copy specific cells to another sheet, lock button if cell has text
    By elmerg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-14-2014, 02:10 AM
  5. Macro button to copy data from one sheet to another sheet's next available column
    By Alice21 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-23-2013, 08:02 AM
  6. Creating a copy button to copy range of cells to a different sheet
    By 5degrees in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-15-2013, 12:21 PM
  7. Replies: 0
    Last Post: 03-13-2013, 03:14 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