Run-time error '9' Subscript out of Range Help

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I am getting a "Run-time error '9': Subscript out of range" on the following code:
Code:
Worksheets("Exhibit ""I""").Activate
The worksheet name is Exhibit "I". If I remember correctly about what that run-time error means, on this line of code its saying it can't find a sheet with that name to activate. I have a feeling it has something to due with all the quotes around the letter (I). Unfortunately, I can not rename this spreadsheet because it is within a public file on a server and I'm not the author of it. I tried different ways to change the worksheet name like adding in single quotes(') instead of double quotes(") but VBA would change that line of code to RED Letters. The only way I could rename the worksheet above so that entire line of code wouldn't be in RED Letters was to position the quotes as shown above. But it still gave me a Run-time error '9'. I never dealt with worksheet names with quotes in them so I'm at a loss on to fix this error. Thank you.
 
I know it returns the Activesheet name and its length but how is this code used to debug(troubleshoot)? Thank You.
It shows that you have a space at the end of the sheet name (hence the inclusion of the | at the start & end).
Also I added the length of the string to show if there was 1 or more spaces inside the file name.
Try
Code:
Worksheets("Exhibit " & """I""" & " ").Activate
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Thank you all very much for your help and for the troubleshooting/debug code tip.
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Quick question there is a second part to my code similarly to the above problem that I forgot to mention in the very first post. Do I need to create a new thread for this problem?
Sorry and Thank you.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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