Subscript out of range after switching to Excel 2011

empirical_psych

New Member
Joined
Aug 10, 2008
Messages
15
Hello all,
I'm trying to run macros in Excel 2011 (Mac) that worked fine in Excel 2004 (Mac). I have OS 10.6 on a Macbook Pro.

The line of code causing the error is:

Trial = Worksheets(Subject).Cells(I, 1).Value

Where subject is string containing numbers (e.g. 801); I is an integer and a counter in a loop that begins at 2; Trial is a string; and the contents of the referenced cell is the string "Trial001". The code is in a macro-enabled workbook, and it's acting on a tab delimited text file opened in excel with the name Subject & ".txt" and the sheet named Subject (again, a string with numbers like 801).
I've determined that there aren't extra spaces in Subject, that Subject is "801" when the error occurs and that this matches the sheet name that is displayed in the tab, and that I is indeed 2.
Any advice would be greatly appreciated.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,300
Office Version
  1. 365
Platform
  1. Windows
So the sheet is named 801 - nothing else.

It's possible that VBA could be interpreting that as a worksheet index rather than name.

Try using CStr(Subject) to convert to a string.
 

Forum statistics

Threads
1,136,969
Messages
5,678,875
Members
419,787
Latest member
juanam

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