Runtime Error 9 Subscript Out of Range ... sometmes?

ColoKevMan

New Member
Joined
Jun 26, 2015
Messages
9
Office Version
  1. 365
Platform
  1. Windows
The below code runs flawlessly on my laptop. When a co-worker, on same network with same access/permissions, runs the macro, it gets the Runtime Error 9 on the Master.Sheets("Buyers IRs").Select row. It's like it can't find the worksheet, but it does easily on my machine. Thoughts?

VBA Code:
Sub CopyBuyersIRsc()
' Copy Buyers IR tab from Master
Application.ScreenUpdating = False
Dim Currentwb As Workbook
Dim Master As Workbook
Set Currentwb = ThisWorkbook
Set Master = Workbooks.Open("some sharepoint link/workbook name")
Dim lRowEnd As Long
'
    Master.Sheets("Buyer IRs").Select
    Sheets("Buyer IRs").Copy After:=Currentwb.Sheets("Sherry C")
lRowEnd = Range("A60000").End(xlUp).Row
    Range("$K$2:$K$" & [lRowEnd]).Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
       :=False, Transpose:=False
    Master.Close savechanges:=True
    Sheets("Sherry C").Activate
    Range("G9").Select
Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:
@NdNoviceHlp I have no doubt your suggestion is a much more efficient way to accomplish that copy. But that is not where the Run-time error is occurring. Per the highlight from the Debug on the Run-time error, it is the "Master.Sheets("Buyer IRs").Select" line that is throwing the error. Again, the code runs fine on my laptop, errors when a coworker initiates the same macro from the same workbook.

You should at least give my code a try to help you undersand where things are going wrong with yours.
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
@NdNoviceHlp
Since the forum's underlying software was changed 3 or 4 years ago, the available code tags have changed. Perhaps you could have a look at the currently available options - see info & link in my signature block. Compare the code formatting in posts 7 & 8 to see some of the differences.
 
Upvote 0
Hmmm... member since 2002, almost 3600 posts... I guess you could say that I'm a bit old school. I guess I could trial to fancy things up but I'm fairly sure it won't improve my coding (unfortunately) :) Have a nice day @Peter_SSs Dave
 
Upvote 0
You should at least give my code a try to help you undersand where things are going wrong with yours.
Thanks rlv01!! Your code did indeed isolate that the "Buyers IRs" worksheet was the issue. All I did was look at the path to the sharepoint site where the workbook is located. It has some special characters (?, =,) after the filename.extension. I included those characters in the vba and it seems to work. Really appreciate the insight. I will have to research the differences between implied and explicit ranges.
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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