Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It might help if you identified the sheet. Why not just use the vlookup
function. -- Don Guillett SalesAid Software 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. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
ISERROR on VLOOKUP | Excel Worksheet Functions | |||
Iserror and vlookup | Excel Worksheet Functions | |||
ISERROR VLOOKUP | Excel Worksheet Functions | |||
Iserror and Vlookup | Excel Worksheet Functions | |||
Can I use ISERROR with VLOOKUP function? | Excel Programming |