Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default vlookup with iserror

Hi, all.

I have the following code which will take a string and search for it in
another worksheet.

once found, it will retrieve the next columns numeric figure.

Function ReplaceValue(ByVal AccStr As String) As Double

'This function will replace the column with the amount found in the
another excel worksheetdata

Dim Amt As Variant

ReplaceValue = 0

Dim Table As Range
Set Table = ThisWorkbook.Worksheets("Sheet").Range("A1:B15000" )

Amt = WorksheetFunction.VLookup(AccStr, Table, 2, False)

If IsError(Amt) Then
ReplaceValue = 0
Else
ReplaceValue = Amt
End If

End Function

If found, it will retrieve the figure. Not found, the code is suppose
to returns 0. but the cell is showing '#VALUE!'. Anyone have any
advise?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default vlookup with iserror

Function ReplaceValue(ByVal AccStr As String) As Double

'This function will replace the column with the amount found in the another
excel worksheetdata

Dim Amt As Variant

ReplaceValue = 0

Dim Table As Range
Set Table = ThisWorkbook.Worksheets("Sheet3").Range("A1:B15000 ")

Amt = Application.VLookup(AccStr, Table, 2, False)

If IsError(Amt) Then
ReplaceValue = 0
Else
ReplaceValue = Amt
End If

End Function



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

wrote in message
oups.com...
Hi, all.

I have the following code which will take a string and search for it in
another worksheet.

once found, it will retrieve the next columns numeric figure.

Function ReplaceValue(ByVal AccStr As String) As Double

'This function will replace the column with the amount found in the
another excel worksheetdata

Dim Amt As Variant

ReplaceValue = 0

Dim Table As Range
Set Table = ThisWorkbook.Worksheets("Sheet").Range("A1:B15000" )

Amt = WorksheetFunction.VLookup(AccStr, Table, 2, False)

If IsError(Amt) Then
ReplaceValue = 0
Else
ReplaceValue = Amt
End If

End Function

If found, it will retrieve the figure. Not found, the code is suppose
to returns 0. but the cell is showing '#VALUE!'. Anyone have any
advise?

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default vlookup with iserror

Try changing this:
Amt = WorksheetFunction.VLookup(AccStr, Table, 2, False)
to
Amt = application.VLookup(AccStr, Table, 2, False)

worksheetfunction.vlookup() causes a run time error that you have to program
around.

application.vlookup() returns an error that you can check.

If you really wanted to use worksheetfunction.vlookup(), you could use something
like:

On Error Resume Next
Amt = WorksheetFunction.VLookup(AccStr, Table, 2, False)
If Err.Number < 0 Then
amt = 0
err.clear
end if

ReplaceValue = Amt





wrote:

Hi, all.

I have the following code which will take a string and search for it in
another worksheet.

once found, it will retrieve the next columns numeric figure.

Function ReplaceValue(ByVal AccStr As String) As Double

'This function will replace the column with the amount found in the
another excel worksheetdata

Dim Amt As Variant

ReplaceValue = 0

Dim Table As Range
Set Table = ThisWorkbook.Worksheets("Sheet").Range("A1:B15000" )

Amt = WorksheetFunction.VLookup(AccStr, Table, 2, False)

If IsError(Amt) Then
ReplaceValue = 0
Else
ReplaceValue = Amt
End If

End Function

If found, it will retrieve the figure. Not found, the code is suppose
to returns 0. but the cell is showing '#VALUE!'. Anyone have any
advise?

Thanks.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default vlookup with iserror

hi, Bob. your solution works. thanks.

Bob Phillips wrote:
Function ReplaceValue(ByVal AccStr As String) As Double

'This function will replace the column with the amount found in the another
excel worksheetdata

Dim Amt As Variant

ReplaceValue = 0

Dim Table As Range
Set Table = ThisWorkbook.Worksheets("Sheet3").Range("A1:B15000 ")

Amt = Application.VLookup(AccStr, Table, 2, False)

If IsError(Amt) Then
ReplaceValue = 0
Else
ReplaceValue = Amt
End If

End Function



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

wrote in message
oups.com...
Hi, all.

I have the following code which will take a string and search for it in
another worksheet.

once found, it will retrieve the next columns numeric figure.

Function ReplaceValue(ByVal AccStr As String) As Double

'This function will replace the column with the amount found in the
another excel worksheetdata

Dim Amt As Variant

ReplaceValue = 0

Dim Table As Range
Set Table = ThisWorkbook.Worksheets("Sheet").Range("A1:B15000" )

Amt = WorksheetFunction.VLookup(AccStr, Table, 2, False)

If IsError(Amt) Then
ReplaceValue = 0
Else
ReplaceValue = Amt
End If

End Function

If found, it will retrieve the figure. Not found, the code is suppose
to returns 0. but the cell is showing '#VALUE!'. Anyone have any
advise?

Thanks.


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
ISERROR on VLOOKUP b1llt Excel Worksheet Functions 3 March 30th 10 03:24 PM
Iserror and vlookup T De Villiers Excel Worksheet Functions 1 January 27th 06 04:00 PM
ISERROR VLOOKUP Carole O Excel Worksheet Functions 1 June 1st 05 02:08 AM
Iserror and Vlookup ShineboxNJ Excel Worksheet Functions 1 November 18th 04 11:31 PM
Can I use ISERROR with VLOOKUP function? Prabha Excel Programming 0 September 20th 04 03:29 PM


All times are GMT +1. The time now is 06:52 PM.

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

About Us

"It's about Microsoft Excel"