PC Review


Reply
Thread Tools Rate Thread

Copy worksheet and rename to next month

 
 
Jock
Guest
Posts: n/a
 
      23rd Feb 2009
When sheet called 'January' is complete, I have set up a command button which
when clicked, will create a new sheet which is to be named as the following
month - in this case 'February'.
How do I tweak the following code to name the new sheet by the correct month?

Sub CopyShtPlus1Month()
Dim shtName As String, newShtName As String
shtName = ActiveSheet.Name
newShtName = ActiveSheet.Name + WHAT DO I ADD HERE???
If Not SheetExists(newShtName) Then
ActiveSheet.Copy After:=ActiveSheet
ActiveSheet.Name = newShtName
Sheets(newShtName).Activate
Range("C7:M43").Select
Selection.ClearContents
Range("C9").Select
Else
MsgBox "You've already created a sheet for this month.", vbCritical
End If

End Sub

Thanks for suggestions
--
Traa Dy Liooar

Jock
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      23rd Feb 2009
Just create an array and use the next item in the array:

Sub CopyShtPlus1Month()
Dim shtName As String, newShtName As String
Dim s(20) As String
s(0) = "January"
s(1) = "February"
s(2) = "March"
s(3) = "April"
s(4) = "May"
s(5) = "June"
s(6) = "July"
s(7) = "August"
s(8) = "September"
s(9) = "October"
s(10) = "November"
s(11) = "December"
shtName = ActiveSheet.Name
For i = 0 To 10
If shtName = s(i) Then
newShtName = s(i + 1)
Exit For
End If
Next

--
Gary''s Student - gsnu200835


"Jock" wrote:

> When sheet called 'January' is complete, I have set up a command button which
> when clicked, will create a new sheet which is to be named as the following
> month - in this case 'February'.
> How do I tweak the following code to name the new sheet by the correct month?
>
> Sub CopyShtPlus1Month()
> Dim shtName As String, newShtName As String
> shtName = ActiveSheet.Name
> newShtName = ActiveSheet.Name + WHAT DO I ADD HERE???
> If Not SheetExists(newShtName) Then
> ActiveSheet.Copy After:=ActiveSheet
> ActiveSheet.Name = newShtName
> Sheets(newShtName).Activate
> Range("C7:M43").Select
> Selection.ClearContents
> Range("C9").Select
> Else
> MsgBox "You've already created a sheet for this month.", vbCritical
> End If
>
> End Sub
>
> Thanks for suggestions
> --
> Traa Dy Liooar
>
> Jock

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      23rd Feb 2009
Try this idea

Sub shtName()
Dim x, y
x = Month(DateValue("1/" & ActiveSheet.Name & "/2009")) + 1
y = Format(DateValue(x & "/1/2008"), "mmmm")
'MsgBox x
'MsgBox y
ActiveSheet.Copy After:=ActiveSheet
ActiveSheet.Name = y
Range("C7:M43").ClearContents

End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Jock" <(E-Mail Removed)> wrote in message
news:66D07AC2-B0EF-45A9-A20C-(E-Mail Removed)...
> When sheet called 'January' is complete, I have set up a command button
> which
> when clicked, will create a new sheet which is to be named as the
> following
> month - in this case 'February'.
> How do I tweak the following code to name the new sheet by the correct
> month?
>
> Sub CopyShtPlus1Month()
> Dim shtName As String, newShtName As String
> shtName = ActiveSheet.Name
> newShtName = ActiveSheet.Name + WHAT DO I ADD HERE???
> If Not SheetExists(newShtName) Then
> ActiveSheet.Copy After:=ActiveSheet
> ActiveSheet.Name = newShtName
> Sheets(newShtName).Activate
> Range("C7:M43").Select
> Selection.ClearContents
> Range("C9").Select
> Else
> MsgBox "You've already created a sheet for this month.", vbCritical
> End If
>
> End Sub
>
> Thanks for suggestions
> --
> Traa Dy Liooar
>
> Jock


 
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
Macro: Copy a worksheet and rename it to a specified value mitch Microsoft Excel Misc 2 16th Feb 2009 05:43 PM
Rename a worksheet after copy... =?Utf-8?B?Q2F0aHkgVw==?= Microsoft Excel Programming 3 8th Mar 2006 06:51 PM
Worksheet copy with rename Doug Broad Microsoft Excel Programming 6 3rd Mar 2006 02:57 PM
copy worksheet from previous month and rename to current month =?Utf-8?B?RGFuIEUu?= Microsoft Excel Programming 4 8th Dec 2005 09:40 PM
How do you copy a worksheet and rename it to a number M Hill Microsoft Excel Worksheet Functions 4 13th Dec 2003 10:13 AM


Features
 

Advertising
 

Newsgroups
 


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