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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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