Solved

Excel VBA - Copy Sheet and rename

Posted on 2013-01-20
3
1,013 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 12

Accepted Solution

by:
Alan3285 earned 500 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 12

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

738 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