Rename Worksheet Function Not Working

charllie

Well-known Member
Joined
Apr 6, 2005
Messages
986
Hi There

I have created the following function which makes a copy of the worksheet "January" and then creates a new sheet.

It then enters the current month in cell C5 and current year in D5 of the new worksheet.

I then want it to rename the sheet to the current month using the value in cell C5. It all works up this stage but i am unable to rename the new worksheet.

The code stops at "ActiveSheet.Name = Range("C5").Value" highligting it yellow.


VBA Code:
Sheets("January").Copy After:=Sheets(Sheets.Count)
    
    Sheets("January (2)").Select
        
    With Range("C5")
        .Value = Date
        .NumberFormat = "mmmm"
    End With
    
    With Range("D5")
        .Value = Date
        .NumberFormat = "yyyy"
    End With

    ActiveSheet.Name = Range("C5").Value

Would appreciate any help in putting this right.

Thanks

Charllie
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
The value in C5 is a date, presumably containing "/" characters (illegal in a sheet name) even though you have formatted it to just show the month.

Try this instead
VBA Code:
ActiveSheet.Name = Range("C5").Text
 
Upvote 0
The value in C5 is a date, presumably containing "/" characters (illegal in a sheet name) even though you have formatted it to just show the month.

Try this instead
VBA Code:
ActiveSheet.Name = Range("C5").Text
Hi Peter

Thank you very much, that works perfectly. Spent ages trying to figure out what i was doing wrong and didnt even thing of that, even after reading the error message.

Thanks again, i appreciate your time.

Charllie
 
Upvote 0
You're welcome. Thanks for the follow-up.

BTW, for the future it would help if you also actually quote the full error message or include a picture of it (as well as the offending code line - which you did. :))
 
Upvote 0
You're welcome. Thanks for the follow-up.

BTW, for the future it would help if you also actually quote the full error message or include a picture of it (as well as the offending code line - which you did. :))
Thanks Peter

Its been a while since i raised an issue on here so forgot the error message but will remember for next time, as there always is a next time :)

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top