Subscript Out of Range Error With Open Workbook

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am having problems with my project. I'm unable to figure out why I keep getting a "Subscript out of range" error with the line highlighted in red below ...

Rich (BB code):
Public wb_data As Workbook

Sub clean_up_database()

    Dim norec As Long 'number of records
    Dim sarah As Long
    Dim myVal As Variant
    
    Set wb_main = Workbooks("Sports15b.xlsm")
    Set ws_vh = wb_main.Worksheets("VAR_HOLD")
    Set ws_th = wb_main.Worksheets("TEMP_HOLD")
    Set ws_rd = wb_main.Worksheets("Rental_Data")
    Set ws_fac = wb_main.Worksheets("Facilities")
    Set ws_front = wb_main.Worksheets("DYNAMIC")
    Set fac1 = ws_fac.Range("A:H")
    Set class1 = ws_fac.Range("B:B")
    
    qfile = ws_vh.Range("B3") & ".xlsx"
        
    Set wb_data = Workbooks(qfile)

The value for qfile is correct.
The workbook having the same value as qfile is open.

Is anyone able to shed any light on perhaps why I am receiving this error?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
What is the value of qfile?

Does it include the path as well as the filename?
 
Upvote 0
Hi Norie,

The value of qfile is simply the workbook name ... "schedule2015_0.xlsx".
It doesn't include the path. I assumed that because the workbook was already open, that that wouldn't be required.

Just as an experiment, I added the path and received the same error.
 
Upvote 0
Are you opening the workbook manually or with code?
 
Upvote 0
For testing purposes I have been opening it manually. Under working circumstances, it would be opened through code in the application.
What's unusual, is I've been testing this module this way for weeks. Only today did I start having this problem. It seems to have started after I added this code ...

Code:
myVal = Application.VLookup(t_fac, fac1, 2, False)
If IsError(myVal) Then
    ws_core.Range("M" & c1).Value = "X"
Else
    ws_core.Range("M" & c1) = myVal
End If

I suppose the workaround would be to put some temp code in this module to open the workbook?
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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