+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    Posts
    103

    Copying a worksheet into a new worksheet

    Hi,

    I thought i'd found the code to do this, but i keep running into execution errors and i have no idea why, what with it being so simple......

    I basically want to create a button on a worksheet that copies the entire contents of the current worksheet being viewed, into a new worksheet at the end of the same workbook.

    ps. I don't want to refer to specific worksheet names as the chances are that names will be changed about..

    Thanks
    Last edited by Barking_Mad; 10-02-2009 at 05:05 AM.

  2. #2
    Registered User
    Join Date
    09-29-2009
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Copying a worksheet into a new worksheet

    Hi Barking_Mad,

    The following code, copies the active sheet, creates a new one, using the default incremental naming scheme, pastes the data to the new sheet, then moves the sheet to the end of all of the worksheets.

    I have fully commented out the code.

    Hope this helps bud

    Code:
    Sub test3()
    
    ' Select the active sheet'
    
    ActiveSheet.Select
        
    'select & copy all data'
    
        Cells.Select
        Selection.Copy
    
    'Add new WS'
    Sheets.Add
        
    'paste copied data into the newsheet'
    
        ActiveSheet.Paste
        
    
    'move the new sheet to the end of all of the sheets using the default naming convention'
    
    ActiveSheet.Move _
           After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
           
           ' selects cell A1 so that it removes the "cells.select"'
           
          Range("A1").Select
          
    
    End Sub

  3. #3
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Copying a worksheet into a new worksheet

    Why not just copy the sheet
    Code:
    ActiveSheet.Copy after:=Sheets(Sheets.Count)
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  4. #4
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    Posts
    103

    Re: Copying a worksheet into a new worksheet

    thanks to both of you that's great

Thread Information

Users Browsing this Thread

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

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.2.0