How to troubleshoot run-time error 9: subscript out of range

krodriguez

Board Regular
Joined
Jul 11, 2012
Messages
119
Hello, I have a code where I'm getting an error on my array ... the code works perfect when array is like this

For Each Ws In Sheets(Array("RLN-Net Realization", "RLN-Red Rev", "RLN-COGS"))

But when I add and extra sheet

For Each Ws In Sheets(Array("RLN-Net Realization", "RLN-Red Rev", "RLN-COGS", WNX-CORP")) I get the error

The name is of the sheet is exactly the same as the one in the code but for some reason the error comes out.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
For Each Ws In Sheets(Array("RLN-Net Realization", "RLN-Red Rev", "RLN-COGS", WNX-CORP")) I get the error
You are missing the double-quote before the last value you entered. It should be:
"WNX-CORP"
 
Upvote 0
Check that all the sheets named in the array are in the active workbook.

Check the sheet names in the array for any misspellings, errant spaces etc.
 
Upvote 0
Select the WNX-CORP sheet & run this
Code:
Sub chk()
MsgBox "|" & ActiveSheet.Name & "|"
End Sub
What do you get?
 
Upvote 0
The error was in one of the sheets name, there was a space right after the sheets's name thus, the code was not reading it correctly.

Issue fixed! thank you
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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