Subscript out of Range Run-time error 9

manthony

New Member
Joined
Dec 5, 2016
Messages
40
Hi,

I am getting a script out of range error message.

I am trying to look up the text in cell B4 on Sheet “Specs.” My table array is a named range call “ContinueWithTask”. ContinueWithTask is columns A:X on a sheet called “Task Names”.

If the vlookup finds the cells is empty, I want it to display a messagebox and exit the macro.

On only declaration is Dim ContinueWithTask As Range

Any ideas? My code is below.

Dim ContinueWithTask As Range

If IsEmpty(Application.WorksheetFunction.VLookup(Sheets(Specs!).Range("B4"), ContinueWithTask, 5, False) = True) Then
MsgBox ("Complete. Please review!")
Exit Sub
End If

Thanks for the help ?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
at first glance it looks like the =TRUE has to be moved outside and what is ContinueWithTask? if its a worksheet range then you need to replace it with sheets("Task Names").range("ContinueWithTask")
 
Upvote 0
Try this.
Code:
Dim ContinueWithTask As Range
Dim Res As Variant

    Res = Application.VLookup(Sheets("Specs").Range("B4"), Sheets("Task Names").Range("A:X"), 5, 0)
    
    If IsError(Res) Then
        MsgBox ("Complete. Please review!")
        Exit Sub
    End If
 
Upvote 0
I think you have some issues with your sheet and range references. If you want to use the named range, do so like this:
Code:
    Dim rng1 As Range
    Dim rng2 As Range
    
    Set rng1 = Sheets("Specs").Range("B4")
    Set rng2 = Range("ContinueWithTask")
    
    If IsEmpty(Application.WorksheetFunction.VLookup(rng1, rng2, 5, False)) Then
        MsgBox ("Complete. Please review!")
        Exit Sub
    End If
 
Upvote 0
Thank you all for the help. VBA Geek you were correct (as were the rest of you). I needed to correct the ContinueWith Task range and move the TRUE. Thank you all so much for the help; it is greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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