Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Vlookup - error handling with VBA

Hi,

Im working on a spreadsheet where I use Vlookup to find a specific value. I
need a code for handling search values that does not exists in the range.
Instead of the standard error code, I want to display a MsgBox with
information that the search string was not found in the range.

Can someone help med with an If sentence?

- Cornelius
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Vlookup - error handling with VBA

Hi
I tend to use

err.clear
on error resume next

' vlookup code
if err.number<0 then
msgbox "LookUp Error"
end if

on error goto 0

The err method lasts for the session, so if you are doing VLookUp in a
loop, you must clear it each time inside the loop as well as before
the loop.

regards
Paul


On Jun 16, 11:16*am, Cornelius
wrote:
Hi,

Im working on a spreadsheet where I use Vlookup to find a specific value. I
need a code for handling search values that does not exists in the range.
Instead of the standard error code, I want to display a MsgBox with
information that the search string was not found in the range.

Can someone help med with an If sentence?

- Cornelius


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Vlookup - error handling with VBA

Thank you Paul!



" wrote:

Hi
I tend to use

err.clear
on error resume next

' vlookup code
if err.number<0 then
msgbox "LookUp Error"
end if

on error goto 0

The err method lasts for the session, so if you are doing VLookUp in a
loop, you must clear it each time inside the loop as well as before
the loop.

regards
Paul


On Jun 16, 11:16 am, Cornelius
wrote:
Hi,

Im working on a spreadsheet where I use Vlookup to find a specific value. I
need a code for handling search values that does not exists in the range.
Instead of the standard error code, I want to display a MsgBox with
information that the search string was not found in the range.

Can someone help med with an If sentence?

- Cornelius



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Vlookup - error handling with VBA

not something I use but think you could use this approach:

myname = "test"
Set lookuprng = Worksheets("Sheet1").Range("A:C")
res = Application.VLookup(myname, lookuprng, 1, False)
If IsError(res) = False Then
MsgBox res
Else
MsgBox (myname & " Not Found")
End If
--
jb


"Cornelius" wrote:

Hi,

Im working on a spreadsheet where I use Vlookup to find a specific value. I
need a code for handling search values that does not exists in the range.
Instead of the standard error code, I want to display a MsgBox with
information that the search string was not found in the range.

Can someone help med with an If sentence?

- Cornelius

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Vlookup - error handling with VBA

Thank you John!




"john" wrote:

not something I use but think you could use this approach:

myname = "test"
Set lookuprng = Worksheets("Sheet1").Range("A:C")
res = Application.VLookup(myname, lookuprng, 1, False)
If IsError(res) = False Then
MsgBox res
Else
MsgBox (myname & " Not Found")
End If
--
jb


"Cornelius" wrote:

Hi,

Im working on a spreadsheet where I use Vlookup to find a specific value. I
need a code for handling search values that does not exists in the range.
Instead of the standard error code, I want to display a MsgBox with
information that the search string was not found in the range.

Can someone help med with an If sentence?

- Cornelius



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Vlookup - error handling with VBA

hi;
i have the same problem and I guess you already explained the solution.
Unfortunately I have no idea of vba.

I went to Microsoft Visual Basic and put in this

myname = "test"
Set lookuprng = Worksheets("Sheet1").Range("A:C")
res = Application.VLookup(myname, lookuprng, 1, False)
If IsError(res) = False Then
MsgBox res
Else
MsgBox (myname & " Not Found")
End If


"myname" is how I want to name the formula right?
what elso do have to change to get it working? And what do I type in in
excel once i finished this?

=myname(?)

Corneluis
(didnot know that my name is so commen)




"Cornelius" wrote:

Thank you John!




"john" wrote:

not something I use but think you could use this approach:

myname = "test"
Set lookuprng = Worksheets("Sheet1").Range("A:C")
res = Application.VLookup(myname, lookuprng, 1, False)
If IsError(res) = False Then
MsgBox res
Else
MsgBox (myname & " Not Found")
End If
--
jb


"Cornelius" wrote:

Hi,

Im working on a spreadsheet where I use Vlookup to find a specific value. I
need a code for handling search values that does not exists in the range.
Instead of the standard error code, I want to display a MsgBox with
information that the search string was not found in the range.

Can someone help med with an If sentence?

- Cornelius

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Vlookup - error handling with VBA

Hi Cornelius,

If you want to use VBA you can try this code. It will display an input box
where you should enter the search value. The corresponding value will then be
returned in a message box. I ended up using the error handling from Paul.

Sub Vlookup()

Dim Search As String
Dim Result As String

'Specify the search range
Set lookuprng = Worksheets("Sheet1").Range("A:C")


'Ask for Search value
Search = InputBox("Insert Search value")
'Error handling if user click cancel
If Search = "" Then
Exit Sub
End If

On Error Resume Next
Result = WorksheetFunction.Vlookup(Search, Range("A:C"), 2, False)

'Error handling if search string is not found
If Err.Number < 0 Then
MsgBox Search & " not found"
Exit Sub
End If
On Error GoTo 0

MsgBox "Value found: " & Result

End Sub

Hope this will help you:)

- Cornelius

"Cornelius" wrote:

hi;
i have the same problem and I guess you already explained the solution.
Unfortunately I have no idea of vba.

I went to Microsoft Visual Basic and put in this

myname = "test"
Set lookuprng = Worksheets("Sheet1").Range("A:C")
res = Application.VLookup(myname, lookuprng, 1, False)
If IsError(res) = False Then
MsgBox res
Else
MsgBox (myname & " Not Found")
End If


"myname" is how I want to name the formula right?
what elso do have to change to get it working? And what do I type in in
excel once i finished this?

=myname(?)

Corneluis
(didnot know that my name is so commen)




"Cornelius" wrote:

Thank you John!




"john" wrote:

not something I use but think you could use this approach:

myname = "test"
Set lookuprng = Worksheets("Sheet1").Range("A:C")
res = Application.VLookup(myname, lookuprng, 1, False)
If IsError(res) = False Then
MsgBox res
Else
MsgBox (myname & " Not Found")
End If
--
jb


"Cornelius" wrote:

Hi,

Im working on a spreadsheet where I use Vlookup to find a specific value. I
need a code for handling search values that does not exists in the range.
Instead of the standard error code, I want to display a MsgBox with
information that the search string was not found in the range.

Can someone help med with an If sentence?

- Cornelius

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error handling VLOOKUP. #N/A - can it be 0 to allow sumation. Richhall Excel Worksheet Functions 3 October 8th 07 12:31 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error Handling vlookup against multiple tables RShow Excel Programming 0 October 5th 05 02:23 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
Vlookup Error handling Gareth[_3_] Excel Programming 1 August 18th 03 07:42 PM


All times are GMT +1. The time now is 06:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"