Worksheet Name rules

Dan Wilson

Well-known Member
Joined
Feb 5, 2006
Messages
546
Office Version
  1. 365
Platform
  1. Windows
Good day. I'm working on a workbook for a friend who is using Excel 2003. I wrote some macros to sort his data. There are 12 worksheets in the workbook and the name of one of them is two words with a space character between. When I try to write a macro using this worksheet name, it won't accept the worksheet name because of the space. How do I get around this besides obviouosly deleting the space in the name? I tried using a dash character, but that won't work either. Are there some rules about naming worksheets? I searched "Learn Excel 2007", but found nothing to help.

As always, help is appreciated.
Thanks, Dan...
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Does this help?

Code:
Sheets.Add.Name = "This Is A Sheet Name"
Sheets("This Is A Sheet Name").Select
 
Upvote 0
Good day Niluj. Thank you for responding to my request. I'm sure that your fix will work within the macro, but the problem is in creating the macro in the first place. The first thing asked for when recording a macro is a name for the macro. This name does not allow any spaces or special characters.
 
Upvote 0
As a follow-up on providing a direct answer to your question:

Without seeing your code it is hard tell tell how you are refering to the Worksheet.

With this "test" and a sheet named My Sheet (with a space in the name) and some other sheet being active at the time of Run:

Code:
Sub myTest()
ActiveWorkbook.Sheets("My Sheet").Select
End Sub

My Sheet becomes the active sheet.

Maybe a view of your code would help to resolve your issue. ;)
 
Upvote 0
Good day Nalani. Thank you for responding to my request. I will review the article that you referenced.
Thanks, Dan...
 
Upvote 0
Good day Niluj. Thank you for responding to my request. I'm sure that your fix will work within the macro, but the problem is in creating the macro in the first place. The first thing asked for when recording a macro is a name for the macro. This name does not allow any spaces or special characters.


The Name of the Macro will not allow Spaces. Therefore the workaround is the Underscore.

Sub my_Test()
code.........
End Sub
 
Upvote 0
The Name of the Macro will not allow Spaces. Therefore the workaround is the Underscore.

Sub my_Test()
code.........
End Sub


You thread was about Worksheet Names. But it seems that you may be having trouble with Nameing Macros as well.

Above will take care of Spaces. But keep in mind that you should not use "reserved" words for Macro Names either.

Example"

Sub Delete() if you wanted to say, delete some Rows

Instead:

Sub myDelete() or

Sub rDelete()

Hope this helps
 
Upvote 0
Good day again Nalani. Thank you for your continued help. Your last reply solved the problem. I was trying too hard. The name of the macro has nothing to do with what the macro does. I knew that the underscore had to fill in any blank spaces, but thought that the worksheet name had to be kept as it was. The fix is to replace the space in the worksheet name with an underscore in the macro title, and then use the workhseet name as it is inside the macro itself. I tend to make things more difficult than they need to be sometimes. I think all is worling now.

Thanks again, Dan...
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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