Subscript Out of Range Error With Open Workbook

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,851
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?
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,264
Office Version
  1. 365
Platform
  1. Windows
What is the value of qfile?

Does it include the path as well as the filename?
 

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,851
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,264
Office Version
  1. 365
Platform
  1. Windows
Are you opening the workbook manually or with code?
 

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,851
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,205
Messages
5,623,363
Members
415,969
Latest member
Rey99

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
Top