Solved

Excel VBA - Copy Sheet and rename

Posted on 2013-01-20
3
957 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
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Alan3285 earned 500 total points
Comment Utility
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
Comment Utility
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 12

Expert Comment

by:Alan3285
Comment Utility
Glad its sorted :-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now