Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default Copy worksheet and rename to next month

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Copy worksheet and rename to next month

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro: Copy a worksheet and rename it to a specified value mitch Excel Discussion (Misc queries) 2 February 16th 09 05:43 PM
Copy worksheet and rename sheet Ernst - EXE Graphics Excel Discussion (Misc queries) 4 July 25th 08 01:18 PM
Rename a worksheet after copy... Cathy W[_2_] Excel Programming 3 March 8th 06 06:51 PM
Worksheet copy with rename Doug Broad[_4_] Excel Programming 6 March 3rd 06 02:57 PM
copy worksheet from previous month and rename to current month Dan E. Excel Programming 4 December 8th 05 09:40 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"