Debug Run-time error '9;" Subscript out of range

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
This code is erroring on row:

Sheets("TaskList").ListObjects(ModelPropricer_vdataNISTaskView).QueryTable.Refresh BackgroundQuery:=False

Dont know why. The sheet name is right and I tried changing the ListObject to the table name as well - no luck

Code:
Sub LoadProposal()
'*Move the Selected Proposal Data to the Selected Proposal Table
Application.ScreenUpdating = False


MsgBox "Before you use this tool you should have entered the PART NUMBER and MTRL CONSOLIDATION Fields in ProPricer/Task"

    Dim sh As Worksheet
    Dim tblPropList As ListObject
    Dim lastRow As ListRow
    Dim lr As Long
    
    Set sh = Sheets("Step 1")
    Set tblPropList = sh.ListObjects("ModelPropricer_vdataProposal")

    lr = Cells(Rows.Count, "B").End(xlUp).Row

    If Intersect(ActiveCell, Range("B16:M" & lr)) Is Nothing Then
        MsgBox "You must select a cell within the applicable Proposal Row.  Select a valid Cell"
    Exit Sub
    End If


    Sheets("Step 1").Range("B" & ActiveCell.Row & ":" & "M" & ActiveCell.Row).Copy
    Sheets("Selected Proposal").Range("A2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        
    Application.CutCopyMode = False
    
    Range("E3").Select
    ActiveCell.Formula2R1C1 = _
        "=""Loaded Proposal: "" & Selected_Proposal[Name] & "": "" & Selected_Proposal[Version]"
        
 'Validate that the user assigned Part Numbers to each Task in ProPricer

    Sheets("TaskList").Visible = True
    Sheets("TaskList").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
    
 Sheets("Step 1").Select
        
        If Sheets("TaskList").Range("X1").Value < 1 Then
            MsgBox "You have not assigned any Part Numbers to your Proposal Task(s). If you do not do so, you will not be able to load your data and you will get error messages if you proceed."
        Else
        
        Sheets("Step 2A").ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
        
        End If
        
 

 Application.ScreenUpdating = True
 
        
MsgBox "The selected proposal has been loaded. Go to Step 2"

End Sub

Thanks!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
That line isn't in your code. If it were, I suspect it should be:

VBA Code:
Sheets("TaskList").ListObjects("ModelPropricer_vdataNISTaskView").QueryTable.Refresh BackgroundQuery:=False
 
Upvote 0
Code:
Sub LoadProposal()
'*Move the Selected Proposal Data to the Selected Proposal Table
Application.ScreenUpdating = False


MsgBox "Before you use this tool you should have entered the PART NUMBER and MTRL CONSOLIDATION Fields in ProPricer/Task"

    Dim sh As Worksheet
    Dim tblPropList As ListObject
    Dim lastRow As ListRow
    Dim lr As Long
   
    Set sh = Sheets("Step 1")
    Set tblPropList = sh.ListObjects("ModelPropricer_vdataProposal")

    lr = Cells(Rows.Count, "B").End(xlUp).Row

    If Intersect(ActiveCell, Range("B16:M" & lr)) Is Nothing Then
        MsgBox "You must select a cell within the applicable Proposal Row.  Select a valid Cell"
    Exit Sub
    End If


    Sheets("Step 1").Range("B" & ActiveCell.Row & ":" & "M" & ActiveCell.Row).Copy
    Sheets("Selected Proposal").Range("A2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
       
    Application.CutCopyMode = False
   
    Range("E3").Select
    ActiveCell.Formula2R1C1 = _
        "=""Loaded Proposal: "" & Selected_Proposal[Name] & "": "" & Selected_Proposal[Version]"
       
       
' Validate that the user assigned Part Numbers to each Task in ProPricer

'XXXXXXX ERROR HERE XXXXXXXXXX Run-time error '9':  Sunscript out of range XXXXXXXX
Sheets("TaskList").ListObjects("ModelPropricer_vdataNISTaskView").QueryTable.Refresh BackgroundQuery:=False
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


 Sheets("Step 1").Select
       
        If Sheets("TaskList").Range("X1").Value < 1 Then
            MsgBox "You have not assigned any Part Numbers to your Proposal Task(s). If you do not do so, you will not be able to load your data and you will get error messages if you proceed."
        Else
       
        End If
       
 

 Application.ScreenUpdating = True
 
       
MsgBox "The selected proposal has been loaded. Go to Step 2"

End Sub
 
Upvote 0
No. That says Listobjects(1)
 
Upvote 0
Rory
I tried both Listobjects(1) and ListObjects("ModelPropricer_vdataNISTaskView") and get and get an error.
 
Upvote 0
Then the most likely cause is that the sheet name is wrong.
 
Upvote 0
Solution
TaskList
ModelPropricer_vdataNISTaskView


I will try Sheet28 and see if that helps
 
Upvote 0
Thanks. changing it to Sheet28 seems to have worked - but I am pretty sure that was the tab name. I copied and pasted it in several times.

But it works now and thats what matters.

Thank you Rory!
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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