PC Review


Reply
Thread Tools Rate Thread

Copy a Sheet to New Sheet Q

 
 
Sean
Guest
Posts: n/a
 
      20th Aug 2007
How would I copy the active Sheet to a newly created Sheet, then
rename "New Sheet" to the value in A5 in the Active sheet, then return
the cursor to the active sheet?

I have essentially a workbook that builds up a new sheet each week
(name of new sheet would be in format dd/mm/yy)


Thanks

 
Reply With Quote
 
 
 
 
Zone
Guest
Posts: n/a
 
      20th Aug 2007
Copy the code below and paste it in a standard module. HTH, James

Sub CopySht()
Dim shtName As String
shtName = ActiveSheet.Name
ActiveSheet.Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = [a5]
Sheets(shtName).Activate
End Sub

"Sean" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> How would I copy the active Sheet to a newly created Sheet, then
> rename "New Sheet" to the value in A5 in the Active sheet, then return
> the cursor to the active sheet?
>
> I have essentially a workbook that builds up a new sheet each week
> (name of new sheet would be in format dd/mm/yy)
>
>
> Thanks
>



 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      20th Aug 2007
On Aug 20, 12:14 pm, "Zone" <KingOfWhi...@aol.com> wrote:
> Copy the code below and paste it in a standard module. HTH, James
>
> Sub CopySht()
> Dim shtName As String
> shtName = ActiveSheet.Name
> ActiveSheet.Copy after:=Sheets(Sheets.Count)
> ActiveSheet.Name = [a5]
> Sheets(shtName).Activate
> End Sub
>
> "Sean" <seanrya...@yahoo.co.uk> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > How would I copy the active Sheet to a newly created Sheet, then
> > rename "New Sheet" to the value in A5 in the Active sheet, then return
> > the cursor to the active sheet?

>
> > I have essentially a workbook that builds up a new sheet each week
> > (name of new sheet would be in format dd/mm/yy)

>
> > Thanks- Hide quoted text -

>
> - Show quoted text -


Thanks James, but I'm hitting debug. Also my value in A5 is in the
format DD/MM/YY, but your code creates a new sheet with the same name
as the 'Original' except an appendix eg Master(1), but I wish to have
the sheet created as 19-08-07, if A5=19/08/07 etc etc

Thanks

 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      20th Aug 2007
Sean, I didn't realize A5 had a date in it. Try changing the
ActiveSheet.Name line to this:

ActiveSheet.Name = Format([a5], "dd-mm-yy")

That should fix the problem. James

"Sean" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Aug 20, 12:14 pm, "Zone" <KingOfWhi...@aol.com> wrote:
>> Copy the code below and paste it in a standard module. HTH, James
>>
>> Sub CopySht()
>> Dim shtName As String
>> shtName = ActiveSheet.Name
>> ActiveSheet.Copy after:=Sheets(Sheets.Count)
>> ActiveSheet.Name = [a5]
>> Sheets(shtName).Activate
>> End Sub
>>
>> "Sean" <seanrya...@yahoo.co.uk> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>>
>>
>> > How would I copy the active Sheet to a newly created Sheet, then
>> > rename "New Sheet" to the value in A5 in the Active sheet, then return
>> > the cursor to the active sheet?

>>
>> > I have essentially a workbook that builds up a new sheet each week
>> > (name of new sheet would be in format dd/mm/yy)

>>
>> > Thanks- Hide quoted text -

>>
>> - Show quoted text -

>
> Thanks James, but I'm hitting debug. Also my value in A5 is in the
> format DD/MM/YY, but your code creates a new sheet with the same name
> as the 'Original' except an appendix eg Master(1), but I wish to have
> the sheet created as 19-08-07, if A5=19/08/07 etc etc
>
> Thanks
>



 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      21st Aug 2007
On Aug 20, 9:54 pm, "Zone" <KingOfWhi...@aol.com> wrote:
> Sean, I didn't realize A5 had a date in it. Try changing the
> ActiveSheet.Name line to this:
>
> ActiveSheet.Name = Format([a5], "dd-mm-yy")
>
> That should fix the problem. James
>
> "Sean" <seanrya...@yahoo.co.uk> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > On Aug 20, 12:14 pm, "Zone" <KingOfWhi...@aol.com> wrote:
> >> Copy the code below and paste it in a standard module. HTH, James

>
> >> Sub CopySht()
> >> Dim shtName As String
> >> shtName = ActiveSheet.Name
> >> ActiveSheet.Copy after:=Sheets(Sheets.Count)
> >> ActiveSheet.Name = [a5]
> >> Sheets(shtName).Activate
> >> End Sub

>
> >> "Sean" <seanrya...@yahoo.co.uk> wrote in message

>
> >>news:(E-Mail Removed)...

>
> >> > How would I copy the active Sheet to a newly created Sheet, then
> >> > rename "New Sheet" to the value in A5 in the Active sheet, then return
> >> > the cursor to the active sheet?

>
> >> > I have essentially a workbook that builds up a new sheet each week
> >> > (name of new sheet would be in format dd/mm/yy)

>
> >> > Thanks- Hide quoted text -

>
> >> - Show quoted text -

>
> > Thanks James, but I'm hitting debug. Also my value in A5 is in the
> > format DD/MM/YY, but your code creates a new sheet with the same name
> > as the 'Original' except an appendix eg Master(1), but I wish to have
> > the sheet created as 19-08-07, if A5=19/08/07 etc etc

>
> > Thanks- Hide quoted text -

>
> - Show quoted text -


Spot on James. One final tweak. It places the new sheet at the end of
my sheet list, how would I place it just to the right of my original
sheet?

Thanks

 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      21st Aug 2007
Change the ActiveSheet.Copy line like this:

ActiveSheet.Copy after:=ActiveSheet


"Sean" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Aug 20, 9:54 pm, "Zone" <KingOfWhi...@aol.com> wrote:
> Spot on James. One final tweak. It places the new sheet at the end of
> my sheet list, how would I place it just to the right of my original
> sheet?
>
> Thanks
>



 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      21st Aug 2007
On Aug 21, 11:41 am, "Zone" <KingOfWhi...@aol.com> wrote:
> Change the ActiveSheet.Copy line like this:
>
> ActiveSheet.Copy after:=ActiveSheet
>
> "Sean" <seanrya...@yahoo.co.uk> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > On Aug 20, 9:54 pm, "Zone" <KingOfWhi...@aol.com> wrote:
> > Spot on James. One final tweak. It places the new sheet at the end of
> > my sheet list, how would I place it just to the right of my original
> > sheet?

>
> > Thanks- Hide quoted text -

>
> - Show quoted text -


Thanks for your help James

 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      21st Aug 2007
On Aug 21, 12:55 pm, Sean <seanrya...@yahoo.co.uk> wrote:
> On Aug 21, 11:41 am, "Zone" <KingOfWhi...@aol.com> wrote:
>
>
>
>
>
> > Change the ActiveSheet.Copy line like this:

>
> > ActiveSheet.Copy after:=ActiveSheet

>
> > "Sean" <seanrya...@yahoo.co.uk> wrote in message

>
> >news:(E-Mail Removed)...

>
> > > On Aug 20, 9:54 pm, "Zone" <KingOfWhi...@aol.com> wrote:
> > > Spot on James. One final tweak. It places the new sheet at the end of
> > > my sheet list, how would I place it just to the right of my original
> > > sheet?

>
> > > Thanks- Hide quoted text -

>
> > - Show quoted text -

>
> Thanks for your help James- Hide quoted text -
>
> - Show quoted text -


James can I test your knowledge again? If an attempt was made to
create a sheet with the same name / date (which I can't have). How in
this instance if it happened could I cancel out of the macro with a
message box saying "You have already created this week"?

Thanks

 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      21st Aug 2007
Sean, change it like this and add the new function as shown. James

Sub CopySht()
Dim shtName As String, newShtName As String
shtName = ActiveSheet.Name
newShtName = Format([a5], "dd-mm-yy")
If Not SheetExists(newShtName) Then
ActiveSheet.Copy after:=ActiveSheet
ActiveSheet.Name = newShtName
Sheets(shtName).Activate
Else
MsgBox "You have already created this week.", vbCritical
End If
End Sub

Private Function SheetExists(sname) As Boolean
'from John Walkenbach
Dim x As Object
On Error Resume Next
Set x = ActiveWorkbook.Sheets(sname)
If Err = 0 Then SheetExists = True _
Else SheetExists = False
End Function

> James can I test your knowledge again? If an attempt was made to
> create a sheet with the same name / date (which I can't have). How in
> this instance if it happened could I cancel out of the macro with a
> message box saying "You have already created this week"?
>
> Thanks
>



 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      21st Aug 2007
On Aug 21, 6:25 pm, "Zone" <KingOfWhi...@aol.com> wrote:
> Sean, change it like this and add the new function as shown. James
>
> Sub CopySht()
> Dim shtName As String, newShtName As String
> shtName = ActiveSheet.Name
> newShtName = Format([a5], "dd-mm-yy")
> If Not SheetExists(newShtName) Then
> ActiveSheet.Copy after:=ActiveSheet
> ActiveSheet.Name = newShtName
> Sheets(shtName).Activate
> Else
> MsgBox "You have already created this week.", vbCritical
> End If
> End Sub
>
> Private Function SheetExists(sname) As Boolean
> 'from John Walkenbach
> Dim x As Object
> On Error Resume Next
> Set x = ActiveWorkbook.Sheets(sname)
> If Err = 0 Then SheetExists = True _
> Else SheetExists = False
> End Function
>
>
>
> > James can I test your knowledge again? If an attempt was made to
> > create a sheet with the same name / date (which I can't have). How in
> > this instance if it happened could I cancel out of the macro with a
> > message box saying "You have already created this week"?

>
> > Thanks- Hide quoted text -

>
> - Show quoted text -


James, I'm getting a debug on line "If Not SheetExists(newShtName)
Then", saying sub or function not defined

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for values in a sheet and copy found records one after theother in another sheet AndreasHermle Microsoft Excel Programming 12 17th Jun 2011 08:12 PM
Auto copy cell data from source sheet to another wrkbook sheet IVLUTA Microsoft Excel Programming 2 2nd Jun 2009 05:07 PM
Auto Copy/autofill Text from sheet to sheet if meets criteria Joyce Microsoft Excel Misc 0 20th Nov 2008 11:05 PM
Help: auto-copy entire rows from 1 sheet (based on cell criteria) to another sheet. bertbarndoor Microsoft Excel Programming 4 5th Oct 2007 04:00 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. =?Utf-8?B?Um9uTWM1?= Microsoft Excel Misc 9 3rd Feb 2005 12:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:52 PM.