Subscript Out Of Range Error

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
845
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a workbook called "Project" and in it there is a macro that pulls data out of another workbook called "Operations Report."

The macro works fine on my laptop. When I run the macro, I make sure that both workbooks are open, (and they are also saved in the same directory - not sure that matters).

I sent the two workbooks to a colleague and when she opens them both and runs the macro, she gets a "run error 9 subscript out of range" error. She too has saved them to the same directory.

Can anyone suggest why she might be getting the error when I do not? Here is the line where hers trips up:

With Workbooks("Operations Report").Worksheets("Sheet2")

I assume that the macro is not finding the "Operations Report" workbook.

Are there some checks we could do or test lines of code I could send to her to diagnise the problem?

Thanks,

MikeG
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Have your friend try including the extension:

With Workbooks("Operations Report.xls").Worksheets("Sheet2")
 
Upvote 0
Thanks Gary and GTO - I'll check both of these and get back.

MikeG
 
Upvote 0
Unfortunately, she still gets the same area - even with the extension. And she is only running one incidence of Excel.

By the way, we are both using Excel 2007.

Mike
 
Upvote 0
I tried it with XL2000. I found I need the .xls extension and both workbooks open in the same instance of Excel before I could switch between the two books via code.

Can't think of anything else to try at the moment.

Gary
 
Upvote 0
I agree with Gary. Other than the obvious (she renamed teh wb), I wonder if she inadvertantly is getting two instances.

In the wb w/the code, have her run:
Code:
Sub ListWBs()
Dim wb As Workbook
    
    For Each wb In Workbooks
        MsgBox ">" & wb.Name & "<"
        ' or Debug.Print ">" & wb.Name & "<"
    Next
End Sub
 
Upvote 0
I agree with Gary. Other than the obvious (she renamed teh wb), I wonder if she inadvertantly is getting two instances.

In the wb w/the code, have her run:
Code:
Sub ListWBs()
Dim wb As Workbook
    
    For Each wb In Workbooks
        MsgBox ">" & wb.Name & "<"
        ' or Debug.Print ">" & wb.Name & "<"
    Next
End Sub

Thanks - nice macro.

I've put it in the workbook and sent to my co-worker.

Mike
 
Upvote 0
Thanks - nice macro.

I've put it in the workbook and sent to my co-worker.

Mike

GTO:

My co-worker just ran the macro and it did list the "Operations Report.xls" workbook - so it does seem to be available. (I was hoping it wouldn't, because that might have made it easier to solve."

Thanks

MikeG
 
Upvote 0
Unfortunately, she still gets the same area - even with the extension. And she is only running one incidence of Excel.

By the way, we are both using Excel 2007.

Mike

Maybe try referencing the sheet differently?

With Workbooks("Operations Report.xls").Sheets("Sheet2")
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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