Inexplicable Subscript out of range error forWorksheet reference

svendfj

Board Regular
Joined
Mar 19, 2011
Messages
99
Office Version
  1. 2016
Platform
  1. Windows
Thanks in advance for any help. I have never seen anything like this before. I have a Workbook ("WBName") with VBA code that has been working fine for months. Now, for no apparent reason, it gets stuck on the following statement:

Set sh1 = Workbooks("WBName").Worksheets("MAIN")

The debugger says:
Workbooks("WBName").Works...= <subscript out="" of="" range=""><subscript out="" of="" range="">Subscript out of range

Which is crazy, because the Worksheet "MAIN" is still there like it always has been. I run across the same error from identical, earlier versions of the program that had worked fine. Also, the problem is the same for any legitimate worksheet name referenced within the parentheses. (That is "MAIN" can be replaced with the name of any other worksheet in the WB, and I get the same error.

Thanks again, Sven

</subscript></subscript>
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Maybe it is the workbook that is the problem, instead of the worksheet, Is the Workbook open? If WBName is a variable and you have it enclosed in quote marks, it will throw the error.
 
Upvote 0
Maybe it is the workbook that is the problem, instead of the worksheet, Is the Workbook open? If WBName is a variable and you have it enclosed in quote marks, it will throw the error.


Thanks JLGWhiz. "WBName" is just the current name of the main workbook (that I have simplified to "WBName").

Also, for example, the following statement also suddenly now does not work:
Workbooks("WBName").Activate

This statement is in a loop that copies from a series of excel documents in a special folder and pastes the information into the respective worksheets of the WB. After copying from each excel document, this statement has been the means to get back to the main WB.

I have a repository of prior WBs that I have saved, going back weeks, each the same except that the data for each week varies. These all worked perfectly at the time, and never generated any error such as what I am getting now. But now, mysteriously, they all show the same problem now.

Thanks again, Sven
 
Upvote 0
Unless you have your system set to hide file extensions, the workbook name will need the file extension added (.xls, xlsx, xlsm, etc.) That is why I thought "WBName" might be a variable.
 
Upvote 0

Forum statistics

Threads
1,222,017
Messages
6,163,406
Members
451,835
Latest member
kristianb63

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