Solved

Excel VBA - Copy Sheet and rename

Posted on 2013-01-20
3
985 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

832 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