Mismatch Msgbox

Ruca13

Board Regular
Joined
Oct 13, 2016
Messages
85
Hi,

I'm using vlookup and sometimes I get the mismatch error because the cell it retrieves has an error (NA to be more precise), which is ok, but I want to get an msgbox and exit the sub when that happens.

This is the part of the code where I have the vlookup:

Code:
Dim price As Double


price = Application.VLookup(Location, lk_range, 10, False)


If IsError(price) Then
MsgBox ("The price is not available for that location")
ActiveWorkbook.Close
Exit Sub
End If

Thank you.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Location is:

Code:
Location = Cells(ActiveCell.Row, 16).Value

It's location i'm searching. I've stored it as a variable because it's not in the file I'm searching.

lk_range:

Code:
Dim lk_range As Range

Set lk_range = Range(Cells(8, 2), Cells(Cells(8, 2).End(xlDown).Row, 15))

The file where I'm searching is not always the same, but the starting row and columns to search are the same, so the only flexible part is the last row of the range.
 
Upvote 0
Surely if price returns and error, the code will stop there and you will not be able to do anything further. Why not precede the lookup with On Error goto?
 
Upvote 0
Change to:

Code:
Dim price As Variant

and the code should then run.
 
Upvote 0

Forum statistics

Threads
1,216,146
Messages
6,129,142
Members
449,488
Latest member
qh017

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