?
Solved

Excel VBA - Copy Sheet and rename

Posted on 2013-01-20
3
Medium Priority
?
1,045 Views
Last Modified: 2013-01-20
Hello Experts,

I have my code to copy the current sheet and rename it.  It is module.  But for some reason it will not let me rename it.  I keeps erroring out saying I can not duplicate a sheet name.  

I assume when I add a sheet, or copy a sheet the "new" sheet is the active sheet.  Here is my code:

Public Sub ADDMONTH()
   
    With ActiveWorkbook.Sheets
   
        ActiveSheet.Copy After:=Sheets(Sheets.Count)
       
    End With
     
    Range("L3").ClearContents
    Range("L3").Value = ActiveSheet.Previous.Range("L3").Value + 1
       
    ActiveSheet.Name = Format(ActiveSheet.Range("L3"), "mmmm")

end sub

What could I being doing wrong or what have I missed?

Any help would be appreciated -
Thanks
0
Comment
Question by:mike637
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Alan earned 2000 total points
ID: 38799502
Do you have another worksheet with the same name already earlier in the workbook (the same month from last year perhaps)?

It might be a hidden worksheet, so check for that.

HTH,

Alan.
0
 

Author Closing Comment

by:mike637
ID: 38799514
I found my mistake, I did not have the orignal cell set as readable date so it would not calc correctly.

Thank you for responding though.  The points are yours.

Michael
0
 
LVL 13

Expert Comment

by:Alan
ID: 38799545
Glad its sorted :-)
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question