Subscript out of range error in query table code

dhouseknecht

New Member
Joined
Jul 28, 2009
Messages
8
Hi All,

I've scavenged some code from a forum and I'm getting a subscript out of range error and I'm not sure what's going on. I'm really pretty new to VBA so go easy on me please. Also, sorry for the code snippets not being up to snuff in terms of formatting...I couldn't get the MrExcel add in working. Any help is greatly appreciated!!! Thanks in advance

When opening the spreadsheet, it throws a Error 9: Subscript out of range. And if I step through the code, it errors in MonitorQuery.

The code was found here:http://www.mrexcel.com/forum/excel-questions/670259-query-excel-updating-keeping-new-data.html

Code in ThisWorkbook

Private Sub Workbook_Open()​
'--Start monitoring for connection refresh events​
Call Sheets("Data").MonitorQuery​
End Sub​

Initial subset of Code in Sheet 1

Option Explicit​

Private WithEvents qt As QueryTable​
Private vStoredNotes As Variant, vKeysBefore As Variant​
Private sTableName As String, sKeyField As String​
Private sFirstNoteField As String, sLastNoteField As String​

Public Sub MonitorQuery()​
'--initialize module scope variables​
sTableName = "Data"​
sKeyField = "OBJECTID"​
sFirstNoteField = "STATUS"​
sLastNoteField = "COMMENTS"​
On Error GoTo ErrorHandler​
Set qt = Me.ListObjects(sTableName).QueryTable​
Exit Sub​
ErrorHandler:​
MsgBox "Error " & Err & ": " & Error(Err.Number)​
End Sub​
 
Perhaps you could give a hint as to which line causes the error? ;)
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

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