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.
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
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
thanks to both of you that's great![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks