Rename Worksheet Function Not Working

charllie

Well-known Member
Joined
Apr 6, 2005
Messages
981
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
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,364
Office Version
  1. 365
Platform
  1. Windows
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
 

charllie

Well-known Member
Joined
Apr 6, 2005
Messages
981
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
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,364
Office Version
  1. 365
Platform
  1. Windows
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. :))
 

charllie

Well-known Member
Joined
Apr 6, 2005
Messages
981
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,993
Messages
5,622,046
Members
415,875
Latest member
Tarali

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
Top