#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 12
Default VLOOKUP in VBA

I am a beginner in VBA; nevertheless, I already have several working UDF's
in Excel 2003, though.

Why does TGI(A213) gives me "#VALUE!"
- while A213 contains "30/11/2013",
- the formula - in the right module - is :
Option Explicit

Function TGI(ABC As Date) As Single

TGI = Application.WorksheetFunction.VLookup(ABC, _
Range(Workbooks("INDEX.XLS").Worksheets("INDEX").R ange("DBINDEX")),
_
2, _
True)

End Function
- the range DBINDEX in the sheet INDEX in the workbook INDEX.XLS is A2:G470,
and
- in that range cell A373 contains "30/11/2013" ?

Can somebody help me ?



  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,440
Default VLOOKUP in VBA

Declare ABC as Double instead of Date

--
Kind regards,

Niek Otten
Microsoft MVP - Excel


"G.P.N.L. c.v.a." wrote in message
...
I am a beginner in VBA; nevertheless, I already have several working UDF's
in Excel 2003, though.

Why does TGI(A213) gives me "#VALUE!"
- while A213 contains "30/11/2013",
- the formula - in the right module - is :
Option Explicit

Function TGI(ABC As Date) As Single

TGI = Application.WorksheetFunction.VLookup(ABC, _
Range(Workbooks("INDEX.XLS").Worksheets("INDEX").R ange("DBINDEX")),
_
2, _
True)

End Function
- the range DBINDEX in the sheet INDEX in the workbook INDEX.XLS is
A2:G470,
and
- in that range cell A373 contains "30/11/2013" ?

Can somebody help me ?




  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 12
Default VLOOKUP in VBA

Sorry, Niek, doesn't make any difference
Gilbert

"Niek Otten" wrote in message
...
Declare ABC as Double instead of Date

--
Kind regards,

Niek Otten
Microsoft MVP - Excel


"G.P.N.L. c.v.a." wrote in message
...
I am a beginner in VBA; nevertheless, I already have several working UDF's
in Excel 2003, though.

Why does TGI(A213) gives me "#VALUE!"
- while A213 contains "30/11/2013",
- the formula - in the right module - is :
Option Explicit

Function TGI(ABC As Date) As Single

TGI = Application.WorksheetFunction.VLookup(ABC, _

Range(Workbooks("INDEX.XLS").Worksheets("INDEX").R ange("DBINDEX")), _
2, _
True)

End Function
- the range DBINDEX in the sheet INDEX in the workbook INDEX.XLS is
A2:G470,
and
- in that range cell A373 contains "30/11/2013" ?

Can somebody help me ?






  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default VLOOKUP in VBA

How about:

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng = Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")

res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If

End Function

There's a difference between how application.vlookup() and
application.worksheetfunction.vlookup() works.

The first returns an error that can be checked -- that's why I like it.

The second causes a runtime error that has to be avoided with "on error" code.

======
Ps. This assumes that that other workbook is open, has a sheet named Index and
a valid range named DBINDEX.

You may want to add some checks.

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")
On Error GoTo 0

If myRng Is Nothing Then
TGI = "Design error!"
Else
res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If
End If
End Function

=========
And the big problem (that I don't like) is that if a cell in that table is
changed, excel doesn't know to recalculate your function.

You could add
application.volatile
at the top of your function

But even that will mean that your results could be waiting for excel's next
calculation before your function updates.

I guess I'm saying: Don't trust your results until you force a recalc!



"G.P.N.L. c.v.a." wrote:

I am a beginner in VBA; nevertheless, I already have several working UDF's
in Excel 2003, though.

Why does TGI(A213) gives me "#VALUE!"
- while A213 contains "30/11/2013",
- the formula - in the right module - is :
Option Explicit

Function TGI(ABC As Date) As Single

TGI = Application.WorksheetFunction.VLookup(ABC, _
Range(Workbooks("INDEX.XLS").Worksheets("INDEX").R ange("DBINDEX")),
_
2, _
True)

End Function
- the range DBINDEX in the sheet INDEX in the workbook INDEX.XLS is A2:G470,
and
- in that range cell A373 contains "30/11/2013" ?

Can somebody help me ?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 12
Default VLOOKUP in VBA

Thanks, Dave...but, indeed, it says "Not found", but that does of course not
help me.
What can cause this error ?
BTW, just to test, I changed "...(ABC As Date)" into "...(ABC As Variant)",
and then the result is "0" (?). Does that help ?
Sorry for the trouble,
Regards,
Gilbert

"Dave Peterson" wrote in message
...
How about:

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng = Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")

res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If

End Function

There's a difference between how application.vlookup() and
application.worksheetfunction.vlookup() works.

The first returns an error that can be checked -- that's why I like it.

The second causes a runtime error that has to be avoided with "on error"
code.

======
Ps. This assumes that that other workbook is open, has a sheet named
Index and
a valid range named DBINDEX.

You may want to add some checks.

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")
On Error GoTo 0

If myRng Is Nothing Then
TGI = "Design error!"
Else
res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If
End If
End Function

=========
And the big problem (that I don't like) is that if a cell in that table is
changed, excel doesn't know to recalculate your function.

You could add
application.volatile
at the top of your function

But even that will mean that your results could be waiting for excel's
next
calculation before your function updates.

I guess I'm saying: Don't trust your results until you force a recalc!



"G.P.N.L. c.v.a." wrote:

I am a beginner in VBA; nevertheless, I already have several working
UDF's
in Excel 2003, though.

Why does TGI(A213) gives me "#VALUE!"
- while A213 contains "30/11/2013",
- the formula - in the right module - is :
Option Explicit

Function TGI(ABC As Date) As Single

TGI = Application.WorksheetFunction.VLookup(ABC, _

Range(Workbooks("INDEX.XLS").Worksheets("INDEX").R ange("DBINDEX")),
_
2, _
True)

End Function
- the range DBINDEX in the sheet INDEX in the workbook INDEX.XLS is
A2:G470,
and
- in that range cell A373 contains "30/11/2013" ?

Can somebody help me ?


--

Dave Peterson





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default VLOOKUP in VBA

How about:

res = Application.VLookup(cLng(ABC), myRng, 2, True)

You can still pass the ABC variable as a date.



"G.P.N.L. c.v.a." wrote:

Thanks, Dave...but, indeed, it says "Not found", but that does of course not
help me.
What can cause this error ?
BTW, just to test, I changed "...(ABC As Date)" into "...(ABC As Variant)",
and then the result is "0" (?). Does that help ?
Sorry for the trouble,
Regards,
Gilbert

"Dave Peterson" wrote in message
...
How about:

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng = Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")

res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If

End Function

There's a difference between how application.vlookup() and
application.worksheetfunction.vlookup() works.

The first returns an error that can be checked -- that's why I like it.

The second causes a runtime error that has to be avoided with "on error"
code.

======
Ps. This assumes that that other workbook is open, has a sheet named
Index and
a valid range named DBINDEX.

You may want to add some checks.

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")
On Error GoTo 0

If myRng Is Nothing Then
TGI = "Design error!"
Else
res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If
End If
End Function

=========
And the big problem (that I don't like) is that if a cell in that table is
changed, excel doesn't know to recalculate your function.

You could add
application.volatile
at the top of your function

But even that will mean that your results could be waiting for excel's
next
calculation before your function updates.

I guess I'm saying: Don't trust your results until you force a recalc!



"G.P.N.L. c.v.a." wrote:

I am a beginner in VBA; nevertheless, I already have several working
UDF's
in Excel 2003, though.

Why does TGI(A213) gives me "#VALUE!"
- while A213 contains "30/11/2013",
- the formula - in the right module - is :
Option Explicit

Function TGI(ABC As Date) As Single

TGI = Application.WorksheetFunction.VLookup(ABC, _

Range(Workbooks("INDEX.XLS").Worksheets("INDEX").R ange("DBINDEX")),
_
2, _
True)

End Function
- the range DBINDEX in the sheet INDEX in the workbook INDEX.XLS is
A2:G470,
and
- in that range cell A373 contains "30/11/2013" ?

Can somebody help me ?


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 12
Default VLOOKUP in VBA

Works !
Thank you, David !
(But why ?)

"Dave Peterson" wrote in message
...
How about:

res = Application.VLookup(cLng(ABC), myRng, 2, True)

You can still pass the ABC variable as a date.



"G.P.N.L. c.v.a." wrote:

Thanks, Dave...but, indeed, it says "Not found", but that does of course
not
help me.
What can cause this error ?
BTW, just to test, I changed "...(ABC As Date)" into "...(ABC As
Variant)",
and then the result is "0" (?). Does that help ?
Sorry for the trouble,
Regards,
Gilbert

"Dave Peterson" wrote in message
...
How about:

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng =
Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")

res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If

End Function

There's a difference between how application.vlookup() and
application.worksheetfunction.vlookup() works.

The first returns an error that can be checked -- that's why I like it.

The second causes a runtime error that has to be avoided with "on
error"
code.

======
Ps. This assumes that that other workbook is open, has a sheet named
Index and
a valid range named DBINDEX.

You may want to add some checks.

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng = Nothing
On Error Resume Next
Set myRng =
Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")
On Error GoTo 0

If myRng Is Nothing Then
TGI = "Design error!"
Else
res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If
End If
End Function

=========
And the big problem (that I don't like) is that if a cell in that table
is
changed, excel doesn't know to recalculate your function.

You could add
application.volatile
at the top of your function

But even that will mean that your results could be waiting for excel's
next
calculation before your function updates.

I guess I'm saying: Don't trust your results until you force a recalc!



"G.P.N.L. c.v.a." wrote:

I am a beginner in VBA; nevertheless, I already have several working
UDF's
in Excel 2003, though.

Why does TGI(A213) gives me "#VALUE!"
- while A213 contains "30/11/2013",
- the formula - in the right module - is :
Option Explicit

Function TGI(ABC As Date) As Single

TGI = Application.WorksheetFunction.VLookup(ABC, _

Range(Workbooks("INDEX.XLS").Worksheets("INDEX").R ange("DBINDEX")),
_
2, _
True)

End Function
- the range DBINDEX in the sheet INDEX in the workbook INDEX.XLS is
A2:G470,
and
- in that range cell A373 contains "30/11/2013" ?

Can somebody help me ?

--

Dave Peterson


--

Dave Peterson



  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default VLOOKUP in VBA

Dates are misterious beasts!

I don't know why VBA has as much trouble as it does with them.

"G.P.N.L. c.v.a." wrote:

Works !
Thank you, David !
(But why ?)

"Dave Peterson" wrote in message
...
How about:

res = Application.VLookup(cLng(ABC), myRng, 2, True)

You can still pass the ABC variable as a date.



"G.P.N.L. c.v.a." wrote:

Thanks, Dave...but, indeed, it says "Not found", but that does of course
not
help me.
What can cause this error ?
BTW, just to test, I changed "...(ABC As Date)" into "...(ABC As
Variant)",
and then the result is "0" (?). Does that help ?
Sorry for the trouble,
Regards,
Gilbert

"Dave Peterson" wrote in message
...
How about:

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng =
Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")

res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If

End Function

There's a difference between how application.vlookup() and
application.worksheetfunction.vlookup() works.

The first returns an error that can be checked -- that's why I like it.

The second causes a runtime error that has to be avoided with "on
error"
code.

======
Ps. This assumes that that other workbook is open, has a sheet named
Index and
a valid range named DBINDEX.

You may want to add some checks.

Option Explicit
Function TGI(ABC As Date) As Variant

Dim res As Variant
Dim myRng As Range

Set myRng = Nothing
On Error Resume Next
Set myRng =
Workbooks("INDEX.XLS").Worksheets("INDEX").Range(" DBINDEX")
On Error GoTo 0

If myRng Is Nothing Then
TGI = "Design error!"
Else
res = Application.VLookup(ABC, myRng, 2, True)

If IsError(res) Then
TGI = "Not Found"
Else
TGI = res
End If
End If
End Function

=========
And the big problem (that I don't like) is that if a cell in that table
is
changed, excel doesn't know to recalculate your function.

You could add
application.volatile
at the top of your function

But even that will mean that your results could be waiting for excel's
next
calculation before your function updates.

I guess I'm saying: Don't trust your results until you force a recalc!



"G.P.N.L. c.v.a." wrote:

I am a beginner in VBA; nevertheless, I already have several working
UDF's
in Excel 2003, though.

Why does TGI(A213) gives me "#VALUE!"
- while A213 contains "30/11/2013",
- the formula - in the right module - is :
Option Explicit

Function TGI(ABC As Date) As Single

TGI = Application.WorksheetFunction.VLookup(ABC, _

Range(Workbooks("INDEX.XLS").Worksheets("INDEX").R ange("DBINDEX")),
_
2, _
True)

End Function
- the range DBINDEX in the sheet INDEX in the workbook INDEX.XLS is
A2:G470,
and
- in that range cell A373 contains "30/11/2013" ?

Can somebody help me ?

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
If (Vlookup 0) working, but what if Vlookup cell does not exist Steve Excel Worksheet Functions 18 November 18th 09 07:33 PM
VLookUp - Does the VLookUp return the exact information? Cpviv Excel Worksheet Functions 2 October 28th 08 09:57 AM
Vlookup in vlookup - taking the result as array name SupperDuck Excel Worksheet Functions 2 June 2nd 07 11:05 AM
Combine VLOOKUP and IF function so #NA isn't returned as a value from VLOOKUP buffgirl71 Excel Discussion (Misc queries) 12 November 14th 06 11:36 PM
Vlookup info being used without vlookup table attached? Excel Worksheet Functions 0 January 25th 05 10:43 AM


All times are GMT +1. The time now is 06:43 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"