Msgbox if #N/A error

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
Platform
  1. Windows
Hello all

I have a button which when selected executes a VLOOKUP formula.
The result from this VLOOKUP formula is then copy/pasted elsewhere in my worksheet.

I would like a Msgbox to be displayed showing an error if the results of the VLOOKUP is #N/A, in other words if the searched value can't be found ...

Help much appreciated
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Here is a very simple example of code that either pastes the result or issues an error message:

Code:
Sub sample()
  Dim v As Variant
  On Error GoTo kapture
  v = Application.WorksheetFunction.VLookup(Range("A1").Value, Range("B1:C3"), False)
  Range("Z100") = v
  Exit Sub
kapture:
  MsgBox "Vlookup fail to find " & Range("A1").Value
  On Error GoTo 0
End Sub
 
Upvote 0
Hi, can't seem to get it to work...let me explain further

in DATA sheet the VLOOKUP value is in cell H1
the range to search is also in DATA sheet through range J1:K250
the result of the VLOOKUP will be displayed in cell L1

If the result of the VLOOKUP, ie the value in L1 is #N/A then goto sheet2 and issue the error MSGBOX

hope that explains more and thanks again
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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