Copy Existing Worksheet to a new Worksheet and make it current
Hi,
How do I copy "Sheet1" to a new worksheet and make that the currently dimmed worksheet to add to?
Say Sheet6 exists, how do I create Sheet7?
There are several posts on how to copy a sheet but I need copy a sheet to a new sheet number and make it the active sheet for input.
Re: Copy Existing Worksheet to a new Worksheet and make it current
This sure sounds like an Office question, so I moved the thread there. If you are wanting to do that in .NET, then I can move it back, though there isn't really a concept of an active sheet when it comes to a .NET program.
Re: Copy Existing Worksheet to a new Worksheet and make it current
I was guessing the active sheet was dimmed as:
dim xlworksheet As Excel.Worksheet
Is this not correct?
Re: Copy Existing Worksheet to a new Worksheet and make it current
I was guessing the active sheet was dimmed as:
Dim xlworksheet As Excel.Worksheet
Is this not correct?
Re: Copy Existing Worksheet to a new Worksheet and make it current
This just creates a worksheet variable/object that you can use to store data
Code:
Dim xlworksheet As Excel.Worksheet
you then need to store some data in it
Code:
'you can use activeworksheet but i prefer using the sheets codenames for good practice
Set xlWorksheet = Sheet1
as for as copying a sheet you can do something like this
Code:
'this is a very simple way but i dont think you can put the new sheet into a variable directly (i maybe wrong)
Sheets(1).Copy After:=Sheets(1)
'or this method is also straight forward, i added another variable
dim xlnewsheet as excel.worksheet
Set xlnewsheet = sheets.add()
xlnewsheet.name = "NewSheet"
Set xlWorksheet = Sheets(1)
xlworksheet.activate 'this displays the page on screen
xlworksheet.copy
xlnewsheet.activate
xlnewsheet.paste
there are various other methods all basically using variations of the code i just provided, test some out
Re: Copy Existing Worksheet to a new Worksheet and make it current