Subscript out of range error only on certain computers

msmarchingtenor

New Member
Joined
Sep 15, 2014
Messages
3
Hello,

I am running across an issue where I receive the Subscript out of Range Error 9 when trying to execute a macro. Using a identical file, it only happens on half of my coworker's computers, but works just fine on others. Have any of you come across this type of scenario? Could this be an issue of our settings?

Not sure if it is helpful, but here is the section of code the debugger shows (it highlights the second to last line):

'Dim i As Integer

' Take away the .xls from the name


thiflnm = ActiveWorkbook.Name
j = 1
Do Until Mid(thiflnm, j + 1, 1) = "."
j = j + 1
Loop
thiflnm = Left(thiflnm, j)
Workbooks(thiflnm).Sheets("Row Numbers").Columns("A:A").ClearContents
Workbooks(thiflnm).Sheets("Sample").Cells.ClearContents

Thanks for the help!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi,

You don't actually need the name of the workbook to make your code work. This should work as well:
Code:
ActiveWorkbook.Sheets("Row Numbers").Columns("A:A").ClearContents
ActiveWorkbook.Sheets("Sample").Cells.ClearContents

If that fails to work then do you have a sheet named: "Row Numbers"?
 
Upvote 0
I do have a sheet named Row Numbers. That is the reason I am so stumped on this one. I am able to run the exact same file on other computers, so I don't think it has anything to do with the code. I'm guess it's an Excel setting? But I am not familiar with settings.
 
Upvote 0
Did you try using ActiveWorkbook instead?

I don't think you need to remove the extension.

In the code below, the first print statement works but the second fails with a sunscript out of range error:
Code:
Sub x()
    thiflnm = ActiveWorkbook.Name
    Debug.Print Workbooks(thiflnm).Worksheets("Sheet1").Range("A1").Value
    
    j = 1
    Do Until Mid(thiflnm, j + 1, 1) = "."
        j = j + 1
    Loop
    thiflnm = Left(thiflnm, j)
    Debug.Print Workbooks(thiflnm).Worksheets("Sheet1").Range("A1").Value

End Sub
 
Upvote 0
Code:
thiflnm = Replace(ActiveWorkbook.Name, ".xls", "")
Workbooks(thiflnm).Sheets("Row Numbers").Columns("A:A").ClearContents
Workbooks(thiflnm).Sheets("Sample").Cells.ClearContents

Some machines will show the .xls some will not, out of range is because you are looking for a . when it doesn't exist.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
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