Hi,

Add line;

On error resume next

Rgds
Vaibhav J
Sent on my BlackBerry® from Vodafone

-----Original Message-----
From: Raj Mahapatra <rajafs...@gmail.com>
Sender: excel-macros@googlegroups.com
Date: Fri, 10 Dec 2010 10:02:19 
To: <excel-macros@googlegroups.com>
Reply-To: excel-macros@googlegroups.com
Subject: $$Excel-Macros$$ Vlookup in Macro

hi group,

In the following vlookup code in macro, if any object is #N/A in the rng
then "*run time error 1004*"occurs.  In such case, i want that it should
show a message as "*lookfor data is not in the range"*

help me how to put msg box if lookfor is not in the rng.

Sub vlookup()
Dim lookfor As Range
Dim rng As Range
Dim col As Integer

Set lookfor = ActiveCell.Offset(0, 2)
    Set rng = Sheets("MV").Columns("A:C")
    col = 3

    dept_code = Application.WorksheetFunction.vlookup(lookfor, rng, col, 0)
End Sub
Thanks & Regards

Rajesh Mahapatra

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts

Reply via email to